Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DoubleLiteral.cs
1using System;
4
6{
11 {
15 public static readonly DoubleLiteral ZeroInstance = new DoubleLiteral(0);
16
20 public static readonly DoubleLiteral OneInstance = new DoubleLiteral(1);
21
26 : base()
27 {
28 }
29
34 public DoubleLiteral(double Value)
35 : base(Value, CommonTypes.Encode(Value))
36 {
37 }
38
44 public DoubleLiteral(double Value, string StringValue)
45 : base(Value, StringValue)
46 {
47 }
48
52 public static readonly string TypeUri = XmlSchema.@double.OriginalString;
53
57 public override string StringType => TypeUri;
58
64 public override Grade Supports(Type ValueType)
65 {
66 return ValueType == typeof(double) ? Grade.Ok : Grade.NotAtAll;
67 }
68
72 public override double ComparableValue => (double)this.Value;
73
81 public override ISemanticLiteral Parse(string Value, string DataType, string Language)
82 {
83 if (CommonTypes.TryParse(Value, out double d))
84 return new DoubleLiteral(d, Value);
85 else
86 return new CustomLiteral(Value, DataType, Language);
87 }
88
94 public override ISemanticLiteral Encapsulate(object Value)
95 {
96 if (Value is double Typed)
97 return new DoubleLiteral(Typed);
98 else
99 return new StringLiteral(Value?.ToString() ?? string.Empty);
100 }
101
103 public override bool Equals(object obj)
104 {
105 return obj is DoubleLiteral Typed &&
106 Typed.StringValue == this.StringValue;
107 }
108
110 public override int GetHashCode()
111 {
112 return this.StringValue.GetHashCode();
113 }
114 }
115}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:15
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Definition: CommonTypes.cs:48
static readonly DoubleLiteral OneInstance
Double value 1.0
override double ComparableValue
Comparable numeric value.
static readonly DoubleLiteral ZeroInstance
Double value 0.0
override ISemanticLiteral Parse(string Value, string DataType, string Language)
Tries to parse a string value of the type supported by the class..
DoubleLiteral(double Value)
Represents a double literal.
override Grade Supports(Type ValueType)
How well the type supports a given value type.
static readonly string TypeUri
http://www.w3.org/2001/XMLSchema#double
override ISemanticLiteral Encapsulate(object Value)
Encapsulates an object value as a semantic literal value.
DoubleLiteral(double Value, string StringValue)
Represents a double literal.
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