Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Methods.cs
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4using System.Text;
5using System.Threading.Tasks;
11
13{
18 {
28 {
29 }
30
34 public override string FunctionName => nameof(Methods);
35
42 {
43 IElement E = this.Argument.Evaluate(Variables);
44 return this.Evaluate(E, Variables);
45 }
46
52 public override async Task<IElement> EvaluateAsync(Variables Variables)
53 {
54 IElement E = await this.Argument.EvaluateAsync(Variables);
55 return this.Evaluate(E, Variables);
56 }
57
65 {
66 object Obj = Argument.AssociatedObjectValue;
67 if (Obj is null)
68 return ObjectValue.Null;
69
70 List<IElement> Elements = new List<IElement>();
71
72 if (Obj is Type T)
73 {
74 foreach (MethodInfo MI in T.GetRuntimeMethods())
75 {
76 if (MI.IsPublic)
77 Elements.Add(new StringValue(ToString(MI)));
78 }
79
80 return new ObjectVector(Elements);
81 }
82 else
83 {
84 T = Obj.GetType();
85
86 foreach (MethodInfo MI in T.GetRuntimeMethods())
87 {
88 if (MI.IsPublic)
89 {
90 Elements.Add(new StringValue(MI.Name));
91 Elements.Add(new ObjectValue(new MethodLambda(Obj, MI)));
92 }
93 }
94
95 ObjectMatrix M = new ObjectMatrix(Elements.Count / 2, 2, Elements)
96 {
97 ColumnNames = new string[] { "Name", "Lambda" }
98 };
99
100 return M;
101 }
102 }
103
104 private static string ToString(MethodInfo MI)
105 {
106 StringBuilder sb = new StringBuilder();
107 bool First = true;
108
109 sb.Append(MI.Name);
110 sb.Append('(');
111
112 foreach (ParameterInfo PI in MI.GetParameters())
113 {
114 if (First)
115 First = false;
116 else
117 sb.Append(',');
118
119 sb.Append(PI.Name);
120 }
121
122 sb.Append(')');
123
124 return sb.ToString();
125 }
126 }
127}
Class managing a script expression.
Definition: Expression.cs:39
Lambda expression executing object methods.
Definition: MethodLambda.cs:13
Extract the methods of a type or an object.
Definition: Methods.cs:18
override IElement Evaluate(IElement Argument, Variables Variables)
Evaluates the function.
Definition: Methods.cs:64
override string FunctionName
Name of the function
Definition: Methods.cs:34
override IElement Evaluate(Variables Variables)
Evaluates the function.
Definition: Methods.cs:41
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the function.
Definition: Methods.cs:52
Methods(ScriptNode Argument, int Start, int Length, Expression Expression)
Extract the methods of a type or an object.
Definition: Methods.cs:26
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
override string ToString()
Definition: ScriptNode.cs:359
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
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