Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DecimalLiteral.cs
1using System;
4
6{
11 {
16 : base()
17 {
18 }
19
24 public DecimalLiteral(decimal Value)
25 : base(Value, CommonTypes.Encode(Value))
26 {
27 }
28
34 public DecimalLiteral(decimal Value, string StringValue)
35 : base(Value, StringValue)
36 {
37 }
38
42 public const string TypeUri = XmlSchema.Namespace + "decimal";
43
47 public override string StringType => TypeUri;
48
54 public override Grade Supports(Type ValueType)
55 {
56 return ValueType == typeof(decimal) ? Grade.Ok : Grade.NotAtAll;
57 }
58
62 public override double ComparableValue => (double)((decimal)this.Value);
63
71 public override ISemanticLiteral Parse(string Value, string DataType, string Language)
72 {
73 if (CommonTypes.TryParse(Value, out decimal d))
74 return new DecimalLiteral(d, Value);
75 else
76 return new CustomLiteral(Value, DataType, Language);
77 }
78
84 public override ISemanticLiteral Encapsulate(object Value)
85 {
86 if (Value is decimal Typed)
87 return new DecimalLiteral(Typed);
88 else
89 return new StringLiteral(Value?.ToString() ?? string.Empty);
90 }
91
93 public override bool Equals(object obj)
94 {
95 return obj is DecimalLiteral Typed &&
96 Typed.StringValue == this.StringValue;
97 }
98
100 public override int GetHashCode()
101 {
102 return this.StringValue.GetHashCode();
103 }
104 }
105}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Definition: CommonTypes.cs:46
DecimalLiteral(decimal Value)
Represents a decimal literal.
override Grade Supports(Type ValueType)
How well the type supports a given value type.
override ISemanticLiteral Parse(string Value, string DataType, string Language)
Tries to parse a string value of the type supported by the class..
DecimalLiteral(decimal Value, string StringValue)
Represents a decimal literal.
override ISemanticLiteral Encapsulate(object Value)
Encapsulates an object value as a semantic literal value.
const string TypeUri
http://www.w3.org/2001/XMLSchema#decimal
override double ComparableValue
Comparable numeric value.
string StringValue
String representation of value.
Abstract base class for semantic literal numeric values.
Interface for semantic literals.
Grade
Grade enumeration
Definition: Grade.cs:7