5using System.Threading.Tasks;
15 private T evaluatedValue =
default;
16 private bool hasEvaluated =
false;
17 private bool hasEvaluatedValue =
false;
18 private readonly T presetValue;
19 private readonly
bool hasPresetValue;
21 private readonly
string name;
32 this.name = AttributeName;
33 this.presetValue = Value;
34 this.hasPresetValue =
true;
35 this.expression =
null;
36 this.document = Document;
48 this.name = AttributeName;
49 this.document = Document;
51 if (E.HasAttribute(
this.name))
53 string Value = E.GetAttribute(this.name);
57 if (CanEmbedScript && c >= 2 && Value[0] ==
'{' && Value[c - 1] ==
'}')
63 this.presetValue =
default;
64 this.hasPresetValue =
false;
65 this.expression = Exp;
66 Document.Dynamic =
true;
76 if (this.
TryParse(Value, out T ParsedValue))
78 this.presetValue = ParsedValue;
79 this.hasPresetValue =
true;
80 this.expression =
null;
87 this.presetValue =
default;
88 this.expression =
null;
89 this.hasPresetValue =
false;
101 this.name = AttributeName;
102 this.presetValue =
default;
103 this.hasPresetValue =
false;
105 this.document = Document;
107 if (!(this.expression is
null))
108 this.document.Dynamic =
true;
114 public string Name => this.name;
139 public bool Undefined => !this.hasPresetValue && this.expression is
null;
144 public bool Defined => this.hasPresetValue || !(this.expression is
null);
157 public abstract bool TryParse(
string StringValue, out T Value);
167 if (Result is
string s && this.
TryParse(s, out Value))
189 if (this.hasPresetValue)
190 Output.WriteAttributeString(this.name, this.
ToString(this.presetValue));
191 else if (!(this.expression is
null))
192 Output.WriteAttributeString(this.name,
"{" + this.expression.Script +
"}");
201 if (this.hasPresetValue)
202 Output.WriteAttributeString(this.name, this.
ToString(this.presetValue));
203 else if (this.hasEvaluatedValue)
204 Output.WriteAttributeString(this.name, this.
ToString(this.evaluatedValue));
215 if (this.hasPresetValue)
216 return this.presetValue;
217 else if (this.hasEvaluatedValue)
218 return this.evaluatedValue;
219 else if (this.hasEvaluated)
221 else if (this.expression is
null)
227 object Value = await this.expression.EvaluateAsync(Session);
228 if (Value is T Eval || this.
TryConvert(Value, out Eval))
230 this.evaluatedValue = Eval;
231 this.hasEvaluated =
true;
232 this.hasEvaluatedValue =
true;
238 this.hasEvaluated =
true;
244 this.hasEvaluated =
true;
266 else if (!(
Attribute.expression is
null))
273 Attribute.evaluatedValue = Eval;
274 Attribute.hasEvaluated =
true;
275 Attribute.hasEvaluatedValue =
true;
281 Attribute.hasEvaluated =
true;
287 Attribute.hasEvaluated =
true;
298 if (this.hasPresetValue)
299 return this.presetValue?.ToString();
300 else if (this.hasEvaluatedValue)
301 return this.evaluatedValue?.ToString();
302 else if (this.hasEvaluated)
303 return "<Evaluation error>";
304 else if (!(this.expression is
null))
305 return this.expression.Script;
Syntax-related layout exception
Contains a 2D layout document.
Manages an attribute value or expression.
bool Undefined
If the attribute is undefined.
bool HasExpression
If the attribute is defined by an expression.
bool Defined
If the attribute is defined.
bool HasPresetValue
If the attribute has a preset value.
Layout2DDocument Document
Document hosting the attribute.
abstract string ToString(T Value)
Converts a value to a string.
string Name
Attribute name
Attribute(string AttributeName, Expression Expression, Layout2DDocument Document)
Defines an undefined attribute.
virtual bool TryConvert(object Result, out T Value)
Tries to convert script result to a value of type T .
async Task< T > EvaluateAsync(Variables Session, T DefaultValue)
Evaluate the attribute value.
override string ToString()
void Export(XmlWriter Output)
Exports the attribute.
Attribute(string AttributeName, T Value, Layout2DDocument Document)
Manages an attribute value or expression.
void ExportState(XmlWriter Output)
Exports the state of the attribute.
T PresetValue
Preset Value of attribute.
abstract bool TryParse(string StringValue, out T Value)
Tries to parse a string value
static async Task< EvaluationResult< T > > TryEvaluate(Attribute< T > Attribute, Variables Session)
Tries to evaluate the attribute value.
Attribute(XmlElement E, string AttributeName, bool CanEmbedScript, Layout2DDocument Document)
Manages an attribute value or expression.
Result of asynchronous evaluation.
static readonly EvaluationResult< T > Empty
No result
Class managing a script expression.
async Task< object > EvaluateAsync(Variables Variables)
Evaluates the expression, using the variables provided in the Variables collection....