Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ToSingleLiteral.cs
1using System.Numerics;
2using Waher.Content;
6
8{
13 {
18 : base()
19 {
20 }
21
31 {
32 }
33
43 {
45 }
46
50 public override string FunctionName => SingleLiteral.TypeUri;
51
57 public override IElement Convert(object Value)
58 {
59 if (Value is float d)
60 return new SingleLiteral(d);
61 else if (Value is bool b)
62 return new SingleLiteral(b ? 1 : 0);
63 else if (Value is string s)
64 {
65 if (CommonTypes.TryParse(s, out d))
66 return new SingleLiteral(d);
67 }
68 else if (Value is BigInteger i)
69 return new SingleLiteral((float)i);
70 else if (Value is Complex z)
71 {
72 if (z.Imaginary == 0)
73 return new SingleLiteral((float)z.Real);
74 }
75
76 d = System.Convert.ToSingle(Value);
77 return new SingleLiteral(d);
78 }
79 }
80}
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
const string TypeUri
http://www.w3.org/2001/XMLSchema#float
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
override ScriptNode CreateFunction(ScriptNode Argument, int Start, int Length, Expression Expression)
Creates a function node.
ToSingleLiteral(ScriptNode Argument, int Start, int Length, Expression Expression)
Converts a value to a single literal.
override IElement Convert(object Value)
Converts an object to the desired type.
Basic interface for all types of elements.
Definition: IElement.cs:20