Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ToIntegerLiteral.cs
1using System.Numerics;
5
7{
12 {
17 : base()
18 {
19 }
20
30 {
31 }
32
42 {
44 }
45
49 public override string FunctionName => IntegerLiteral.TypeUri;
50
56 public override IElement Convert(object Value)
57 {
58 if (Value is BigInteger i)
59 return new IntegerLiteral(i);
60 else if (Value is double d)
61 return new IntegerLiteral((BigInteger)d);
62 else if (Value is bool b)
63 return new IntegerLiteral(b ? 1 : 0);
64 else if (Value is string s)
65 {
66 if (BigInteger.TryParse(s, out i))
67 return new IntegerLiteral(i);
68 }
69 else if (Value is Complex z)
70 {
71 if (z.Imaginary == 0)
72 return new IntegerLiteral((BigInteger)z.Real);
73 }
74
75 long l = System.Convert.ToInt64(Value);
76 return new IntegerLiteral(l);
77 }
78 }
79}
Represents an integer literal of undefined size.
const string TypeUri
http://www.w3.org/2001/XMLSchema#byte
Class managing a script expression.
Definition: Expression.cs:39
ScriptNode Argument
Function argument.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
ToIntegerLiteral(ScriptNode Argument, int Start, int Length, Expression Expression)
Converts a value to a integer literal.
override ScriptNode CreateFunction(ScriptNode Argument, int Start, int Length, Expression Expression)
Creates a function node.
override IElement Convert(object Value)
Converts an object to the desired type.
Basic interface for all types of elements.
Definition: IElement.cs:20