Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GetAttribute.cs
1using System.Threading.Tasks;
2using System.Xml;
7
9{
14 {
24 : base(Xml, Name, Start, Length, Expression)
25 {
26 }
27
31 public override string FunctionName => nameof(GetAttribute);
32
36 public override string[] DefaultArgumentNames => new string[] { "XML", "Name" };
37
46 {
47 object Obj = Argument1.AssociatedObjectValue;
48 if (Obj is null)
49 return Argument1;
50
51 string Name = Argument2.AssociatedObjectValue?.ToString() ?? string.Empty;
52
53 if (Obj is XmlElement E)
54 return new StringValue(E.GetAttribute(Name));
55 else if (Obj is XmlDocument Doc)
56 return new StringValue(Doc.DocumentElement.GetAttribute(Name));
57 else
58 throw new ScriptRuntimeException("XML element expected.", this);
59 }
60
69 {
70 return Task.FromResult(this.EvaluateScalar(Argument1, Argument2, Variables));
71 }
72 }
73}
Class managing a script expression.
Definition: Expression.cs:39
Base class for funcions of two scalar variables.
ScriptNode Argument2
Function argument 2.
ScriptNode Argument1
Function argument 1.
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
Collection of variables.
Definition: Variables.cs:25
Gets the value of an attribute of an XML Element.
Definition: GetAttribute.cs:14
override string FunctionName
Name of the function
Definition: GetAttribute.cs:31
GetAttribute(ScriptNode Xml, ScriptNode Name, int Start, int Length, Expression Expression)
Gets the value of an attribute of an XML Element.
Definition: GetAttribute.cs:23
override string[] DefaultArgumentNames
Default Argument names
Definition: GetAttribute.cs:36
override IElement EvaluateScalar(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: GetAttribute.cs:45
override Task< IElement > EvaluateScalarAsync(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: GetAttribute.cs:68
Basic interface for all types of elements.
Definition: IElement.cs:20