Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Fields.cs
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4using System.Threading.Tasks;
10
12{
17 {
27 {
28 }
29
33 public override string FunctionName => nameof(Fields);
34
39 public override bool IsAsynchronous => true;
40
47 {
48 return this.EvaluateAsync(Variables).Result;
49 }
50
56 public override async Task<IElement> EvaluateAsync(Variables Variables)
57 {
58 IElement E = await this.Argument.EvaluateAsync(Variables);
59 object Obj = E.AssociatedObjectValue;
60 if (Obj is null)
61 return ObjectValue.Null;
62
63 List<IElement> Elements = new List<IElement>();
64
65 if (Obj is Type T)
66 {
67 foreach (FieldInfo FI in T.GetRuntimeFields())
68 {
69 if (FI.IsPublic)
70 Elements.Add(new StringValue(FI.Name));
71 }
72
73 return new ObjectVector(Elements);
74 }
75 else
76 {
77 T = Obj.GetType();
78
79 foreach (FieldInfo FI in T.GetRuntimeFields())
80 {
81 if (FI.IsPublic)
82 {
83 Elements.Add(new StringValue(FI.Name));
84 Elements.Add(Expression.Encapsulate(await WaitPossibleTask(FI.GetValue(Obj))));
85 }
86 }
87
88 ObjectMatrix M = new ObjectMatrix(Elements.Count / 2, 2, Elements)
89 {
90 ColumnNames = new string[] { "Name", "Value" }
91 };
92
93 return M;
94 }
95 }
96
104 {
105 return ObjectValue.Null;
106 }
107 }
108}
Class managing a script expression.
Definition: Expression.cs:39
static IElement Encapsulate(object Value)
Encapsulates an object.
Definition: Expression.cs:4955
Extract the fields of a type or an object.
Definition: Fields.cs:17
override string FunctionName
Name of the function
Definition: Fields.cs:33
Fields(ScriptNode Argument, int Start, int Length, Expression Expression)
Extract the fields of a type or an object.
Definition: Fields.cs:25
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: Fields.cs:56
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: Fields.cs:39
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: Fields.cs:46
override IElement Evaluate(IElement Argument, Variables Variables)
Evaluates the function.
Definition: Fields.cs:103
Base class for funcions of one 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
static async Task< object > WaitPossibleTask(object Result)
Waits for any asynchronous process to terminate.
Definition: ScriptNode.cs:417
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Definition: ScriptNode.cs:158
static readonly ObjectValue Null
Null value.
Definition: ObjectValue.cs:86
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