Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Properties.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
9
11{
16 {
26 {
27 }
28
32 public override string FunctionName => nameof(Properties);
33
38 public override bool IsAsynchronous => true;
39
46 {
47 return this.EvaluateAsync(Variables).Result;
48 }
49
55 public override async Task<IElement> EvaluateAsync(Variables Variables)
56 {
57 IElement E = await this.Argument.EvaluateAsync(Variables);
58 object Obj = E.AssociatedObjectValue;
59 if (Obj is null)
60 return ObjectValue.Null;
61
62 IPropertyEnumerator Enumerator = GetEnumerator(Obj.GetType());
63
64 if (Enumerator is null)
65 return ObjectValue.Null;
66 else
67 return await Enumerator.EnumerateProperties(Obj);
68 }
69
70 private static readonly Dictionary<Type, IPropertyEnumerator> enumerators = new Dictionary<Type, IPropertyEnumerator>();
71
72 private static IPropertyEnumerator GetEnumerator(Type T)
73 {
74 lock (enumerators)
75 {
76 if (enumerators.TryGetValue(T, out IPropertyEnumerator Enumerator))
77 return Enumerator;
78 }
79
80 IPropertyEnumerator Best = Types.FindBest<IPropertyEnumerator, Type>(T);
81
82 lock (enumerators)
83 {
84 enumerators[T] = Best;
85 }
86
87 return Best;
88 }
89
97 {
98 return ObjectValue.Null;
99 }
100 }
101}
Static class that dynamically manages types and interfaces available in the runtime environment.
Definition: Types.cs:14
Class managing a script expression.
Definition: Expression.cs:39
Extract the properties of a type or an object.
Definition: Properties.cs:16
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: Properties.cs:38
override IElement Evaluate(IElement Argument, Variables Variables)
Evaluates the function.
Definition: Properties.cs:96
override string FunctionName
Name of the function
Definition: Properties.cs:32
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: Properties.cs:55
Properties(ScriptNode Argument, int Start, int Length, Expression Expression)
Extract the properties of a type or an object.
Definition: Properties.cs:24
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: Properties.cs:45
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
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
Task< IElement > EnumerateProperties(object Object)
Enumerates the properties of an object (of a type it supports).