Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
HasAttribute.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(HasAttribute);
32
36 public override string[] DefaultArgumentNames => new string[] { "XML", "Name" };
37
41 public override bool UpgradeScalarsToSameSet => false;
42
51 {
52 object Obj = Argument1.AssociatedObjectValue;
53 if (Obj is null)
54 return Argument1;
55
56 string Name = ToString(Argument2) ?? string.Empty;
57
58 if (Argument1.AssociatedObjectValue is XmlElement E)
59 return E.HasAttribute(Name) ? BooleanValue.True : BooleanValue.False;
60 else if (Argument1.AssociatedObjectValue is XmlDocument Doc)
61 return Doc.DocumentElement.HasAttribute(Name) ? BooleanValue.True : BooleanValue.False;
62 else
63 throw new ScriptRuntimeException("XML element expected.", this);
64 }
65
74 {
75 return Task.FromResult(this.EvaluateScalar(Argument1, Argument2, Variables));
76 }
77 }
78}
Class managing a script expression.
Definition: Expression.cs:41
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
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly BooleanValue False
Constant false value.
Collection of variables.
Definition: Variables.cs:25
Checks if an attribute eixts for an XML Element.
Definition: HasAttribute.cs:14
HasAttribute(ScriptNode Xml, ScriptNode Name, int Start, int Length, Expression Expression)
Checks if an attribute eixts for an XML Element.
Definition: HasAttribute.cs:23
override IElement EvaluateScalar(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: HasAttribute.cs:50
override string[] DefaultArgumentNames
Default Argument names
Definition: HasAttribute.cs:36
override string FunctionName
Name of the function
Definition: HasAttribute.cs:31
override Task< IElement > EvaluateScalarAsync(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: HasAttribute.cs:73
override bool UpgradeScalarsToSameSet
If scalars should be upgraded to the same set before evaluation.
Definition: HasAttribute.cs:41
Basic interface for all types of elements.
Definition: IElement.cs:21