Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
IntegerLiteral.cs
1using System;
2using System.Numerics;
5
7{
12 {
13 private readonly string dataType = null;
14
19 : base()
20 {
21 }
22
27 public IntegerLiteral(BigInteger Value)
28 : base(Value, Value.ToString())
29 {
30 }
31
37 public IntegerLiteral(BigInteger Value, string StringValue)
38 : base(Value, StringValue)
39 {
40 }
41
48 public IntegerLiteral(BigInteger Value, string StringValue, string DataType)
49 : base(Value, StringValue)
50 {
51 this.dataType = DataType;
52 }
53
57 public const string TypeUri = XmlSchema.Namespace + "integer";
58
62 public override string StringType => this.dataType ?? TypeUri;
63
69 public override Grade Supports(Type ValueType)
70 {
71 return ValueType == typeof(BigInteger) ? Grade.Ok : Grade.NotAtAll;
72 }
73
77 public override double ComparableValue => (double)((BigInteger)this.Value);
78
84 public override Grade Supports(string DataType)
85 {
86 switch (DataType)
87 {
88 case IntegerUri:
93 return Grade.Ok;
94
95 default:
96 return Grade.NotAtAll;
97 }
98 }
99
103 public const string IntegerUri = XmlSchema.Namespace + "integer";
104
108 public const string NegativeIntegerUri = XmlSchema.Namespace + "negativeInteger";
109
113 public const string NonNegativeIntegerUri = XmlSchema.Namespace + "nonNegativeInteger";
114
118 public const string NonPositiveIntegerUri = XmlSchema.Namespace + "nonPositiveInteger";
119
123 public const string PositiveIntegerUri = XmlSchema.Namespace + "positiveInteger";
124
125
133 public override ISemanticLiteral Parse(string Value, string DataType, string Language)
134 {
135 if (BigInteger.TryParse(Value, out BigInteger i))
136 return new IntegerLiteral(i, Value, DataType);
137 else
138 return new CustomLiteral(Value, DataType, Language);
139 }
140
146 public override ISemanticLiteral Encapsulate(object Value)
147 {
148 if (Value is BigInteger Typed)
149 return new IntegerLiteral(Typed);
150 else
151 return new StringLiteral(Value?.ToString() ?? string.Empty);
152 }
153
155 public override bool Equals(object obj)
156 {
157 return obj is IntegerLiteral Typed &&
158 Typed.StringValue == this.StringValue;
159 }
160
162 public override int GetHashCode()
163 {
164 return this.StringValue.GetHashCode();
165 }
166
178 public override int CompareTo(object obj)
179 {
180 if (obj is IntegerLiteral Typed)
181 return ((BigInteger)this.Value).CompareTo((BigInteger)Typed.Value);
182 else
183 return base.CompareTo(obj);
184 }
185 }
186}
Represents an integer literal of undefined size.
const string NonNegativeIntegerUri
http://www.w3.org/2001/XMLSchema#nonNegativeInteger
override ISemanticLiteral Encapsulate(object Value)
Encapsulates an object value as a semantic literal value.
IntegerLiteral(BigInteger Value)
Represents an integer literal of undefined size.
IntegerLiteral(BigInteger Value, string StringValue)
Represents an integer literal of undefined size.
const string NegativeIntegerUri
http://www.w3.org/2001/XMLSchema#negativeInteger
IntegerLiteral(BigInteger Value, string StringValue, string DataType)
Represents an integer literal of undefined size.
override double ComparableValue
Comparable numeric value.
override int CompareTo(object obj)
Compares the current instance with another object of the same type and returns an integer that indica...
override ISemanticLiteral Parse(string Value, string DataType, string Language)
Tries to parse a string value of the type supported by the class..
const string IntegerUri
http://www.w3.org/2001/XMLSchema#integer
IntegerLiteral()
Represents an integer literal of undefined size.
override Grade Supports(string DataType)
How well the type supports a given data type.
const string TypeUri
http://www.w3.org/2001/XMLSchema#byte
const string NonPositiveIntegerUri
http://www.w3.org/2001/XMLSchema#nonPositiveInteger
const string PositiveIntegerUri
http://www.w3.org/2001/XMLSchema#positiveInteger
override Grade Supports(Type ValueType)
How well the type supports a given value type.
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