Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TimeLiteral.cs
1using System;
4
6{
11 {
15 public TimeLiteral()
16 : base()
17 {
18 }
19
24 public TimeLiteral(TimeSpan Value)
25 : base(Value, Value.ToString())
26 {
27 }
28
34 public TimeLiteral(TimeSpan Value, string StringValue)
35 : base(Value, StringValue)
36 {
37 }
38
42 public const string TypeUri = XmlSchema.Namespace + "time";
43
47 public override string StringType => TypeUri;
48
54 public override Grade Supports(Type ValueType)
55 {
56 return ValueType == typeof(TimeSpan) ? Grade.Ok : Grade.NotAtAll;
57 }
58
66 public override ISemanticLiteral Parse(string Value, string DataType, string Language)
67 {
68 if (TimeSpan.TryParse(Value, out TimeSpan TP))
69 return new TimeLiteral(TP, Value);
70 else
71 return new CustomLiteral(Value, DataType, Language);
72 }
73
79 public override ISemanticLiteral Encapsulate(object Value)
80 {
81 if (Value is TimeSpan Typed)
82 return new TimeLiteral(Typed);
83 else
84 return new StringLiteral(Value?.ToString() ?? string.Empty);
85 }
86
88 public override bool Equals(object obj)
89 {
90 return obj is TimeLiteral Typed &&
91 Typed.StringValue == this.StringValue;
92 }
93
95 public override int GetHashCode()
96 {
97 return this.StringValue.GetHashCode();
98 }
99 }
100}
TimeLiteral(TimeSpan Value, string StringValue)
Represents a time literal.
Definition: TimeLiteral.cs:34
override Grade Supports(Type ValueType)
How well the type supports a given value type.
Definition: TimeLiteral.cs:54
override ISemanticLiteral Encapsulate(object Value)
Encapsulates an object value as a semantic literal value.
Definition: TimeLiteral.cs:79
const string TypeUri
http://www.w3.org/2001/XMLSchema#time
Definition: TimeLiteral.cs:42
override ISemanticLiteral Parse(string Value, string DataType, string Language)
Tries to parse a string value of the type supported by the class..
Definition: TimeLiteral.cs:66
TimeLiteral(TimeSpan Value)
Represents a time literal.
Definition: TimeLiteral.cs:24
Abstract base class for semantic literal values.
string StringValue
String representation of value.
Interface for semantic literals.
Grade
Grade enumeration
Definition: Grade.cs:7