Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DateTimeLiteral.cs
1using System;
5
7{
12 {
17 : base()
18 {
19 }
20
25 public DateTimeLiteral(DateTimeOffset Value)
26 : base(Value, XML.Encode(Value))
27 {
28 }
29
35 public DateTimeLiteral(DateTimeOffset Value, string StringValue)
36 : base(Value, StringValue)
37 {
38 }
39
43 public const string TypeUri = XmlSchema.Namespace + "dateTime";
44
48 public override string StringType => TypeUri;
49
55 public override Grade Supports(Type ValueType)
56 {
57 return ValueType == typeof(DateTime) ? Grade.Ok : Grade.NotAtAll;
58 }
59
67 public override ISemanticLiteral Parse(string Value, string DataType, string Language)
68 {
69 if (XML.TryParse(Value, out DateTimeOffset TP))
70 return new DateTimeLiteral(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)
83 return new DateTimeLiteral(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 DateTimeLiteral Typed &&
92 Typed.StringValue == this.StringValue;
93 }
94
96 public override int GetHashCode()
97 {
98 return this.StringValue.GetHashCode();
99 }
100 }
101}
DateTimeLiteral(DateTimeOffset Value, string StringValue)
Represents a dateTime literal.
override ISemanticLiteral Encapsulate(object Value)
Encapsulates an object value as a semantic literal value.
DateTimeLiteral(DateTimeOffset Value)
Represents a dateTime literal.
override ISemanticLiteral Parse(string Value, string DataType, string Language)
Tries to parse a string value of the type supported by the class..
override Grade Supports(Type ValueType)
How well the type supports a given value type.
const string TypeUri
http://www.w3.org/2001/XMLSchema#boolean
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