Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Guid.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
7
9{
14 {
24 {
25 }
26
30 public override string FunctionName => nameof(Guid);
31
39 {
40 if (System.Guid.TryParse(Argument, out System.Guid Guid))
41 return new ObjectValue(Guid);
42 else
43 throw new ScriptRuntimeException("Invalid GUID.", this);
44 }
45
53 {
54 object Obj = Argument.AssociatedObjectValue;
55
56 if (Obj is Guid)
57 return Argument;
58 else if (Obj is string s)
59 return this.EvaluateScalar(s, Variables);
60 else if (Obj is byte[] Bin)
61 {
62 if (Bin.Length == 16)
63 return new ObjectValue(new System.Guid(Bin));
64 else
65 throw new ScriptRuntimeException("Invalid number of bytes.", this);
66 }
67 else
68 throw new ScriptRuntimeException("Invalid GUID.", this);
69 }
70
77 public override Task<IElement> EvaluateScalarAsync(IElement Argument, Variables Variables)
78 {
79 return Task.FromResult(this.EvaluateScalar(Argument, Variables));
80 }
81
88 public override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary<string, IElement> AlreadyFound)
89 {
90 object Obj = CheckAgainst.AssociatedObjectValue;
91
92 if (!(Obj is Guid))
93 {
94 if (Obj is string s)
95 {
96 if (System.Guid.TryParse(s, out System.Guid Guid))
97 CheckAgainst = new ObjectValue(Guid);
98 else
99 return PatternMatchResult.NoMatch;
100 }
101 else if (Obj is byte[] Bin)
102 {
103 if (Bin.Length == 16)
104 CheckAgainst = new ObjectValue(new System.Guid(Bin));
105 else
106 return PatternMatchResult.NoMatch;
107 }
108 else
109 return PatternMatchResult.NoMatch;
110 }
111
112 return this.Argument.PatternMatch(CheckAgainst, AlreadyFound);
113 }
114 }
115}
Class managing a script expression.
Definition: Expression.cs:39
override Task< IElement > EvaluateScalarAsync(IElement Argument, Variables Variables)
Evaluates the function on a scalar argument.
Definition: Guid.cs:77
Guid(ScriptNode Argument, int Start, int Length, Expression Expression)
Guid(x)
Definition: Guid.cs:22
override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
Definition: Guid.cs:88
override string FunctionName
Name of the function
Definition: Guid.cs:30
override IElement EvaluateScalar(IElement Argument, Variables Variables)
Evaluates the function on a scalar argument.
Definition: Guid.cs:52
override IElement EvaluateScalar(string Argument, Variables Variables)
Evaluates the function on a scalar argument.
Definition: Guid.cs:38
Base class for funcions of one scalar variable.
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
virtual PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
Definition: ScriptNode.cs:169
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
PatternMatchResult
Status result of a pattern matching operation.
Definition: ScriptNode.cs:17