Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DateLiteral.cs
1using System;
5
7{
12 {
16 public DateLiteral()
17 : base()
18 {
19 }
20
25 public DateLiteral(DateTime Value)
26 : base(Value, XML.Encode(Value, true))
27 {
28 }
29
35 public DateLiteral(DateTime Value, string StringValue)
36 : base(Value, StringValue)
37 {
38 }
39
43 public const string TypeUri = XmlSchema.Namespace + "date";
44
48 public override string StringType => TypeUri;
49
55 public override Grade Supports(Type ValueType)
56 {
57 return Grade.Barely;
58 }
59
67 public override ISemanticLiteral Parse(string Value, string DataType, string Language)
68 {
69 if (XML.TryParse(Value, out DateTime TP))
70 return new DateLiteral(TP, Value);
71 else
72 return new CustomLiteral(Value, DataType, Language);
73 }
74
80 public override ISemanticLiteral Encapsulate(object Value)
81 {
82 if (Value is DateTime Typed && Typed.TimeOfDay == TimeSpan.Zero)
83 return new DateLiteral(Typed);
84 else
85 return new StringLiteral(Value?.ToString() ?? string.Empty);
86 }
87
89 public override bool Equals(object obj)
90 {
91 return obj is DateLiteral Typed &&
92 Typed.StringValue == this.StringValue;
93 }
94
96 public override int GetHashCode()
97 {
98 return this.StringValue.GetHashCode();
99 }
100 }
101}
override Grade Supports(Type ValueType)
How well the type supports a given value type.
Definition: DateLiteral.cs:55
DateLiteral(DateTime Value, string StringValue)
Represents a date literal.
Definition: DateLiteral.cs:35
const string TypeUri
http://www.w3.org/2001/XMLSchema#date
Definition: DateLiteral.cs:43
override ISemanticLiteral Encapsulate(object Value)
Encapsulates an object value as a semantic literal value.
Definition: DateLiteral.cs:80
override ISemanticLiteral Parse(string Value, string DataType, string Language)
Tries to parse a string value of the type supported by the class..
Definition: DateLiteral.cs:67
DateLiteral(DateTime Value)
Represents a date literal.
Definition: DateLiteral.cs:25
Abstract base class for semantic literal values.
string StringValue
String representation of value.
Helps with common XML-related tasks.
Definition: XML.cs:19
static bool TryParse(string s, out DateTime Value)
Tries to decode a string encoded DateTime.
Definition: XML.cs:744
Interface for semantic literals.
Grade
Grade enumeration
Definition: Grade.cs:7