Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FloatAttribute.cs
1using System.Xml;
2using Waher.Content;
3using Waher.Script;
4
6{
10 public class FloatAttribute : Attribute<float>
11 {
18 public FloatAttribute(string AttributeName, float Value, Layout2DDocument Document)
19 : base(AttributeName, Value, Document)
20 {
21 }
22
29 public FloatAttribute(XmlElement E, string AttributeName, Layout2DDocument Document)
30 : base(E, AttributeName, true, Document)
31 {
32 }
33
40 public FloatAttribute(string AttributeName, Expression Expression, Layout2DDocument Document)
41 : base(AttributeName, Expression, Document)
42 {
43 }
44
51 public override bool TryConvert(object Result, out float Value)
52 {
53 if (Result is double d)
54 {
55 Value = (float)d;
56 return true;
57 }
58 else
59 return base.TryConvert(Result, out Value);
60 }
61
68 public override bool TryParse(string StringValue, out float Value)
69 {
70 return CommonTypes.TryParse(StringValue, out Value);
71 }
72
78 public override string ToString(float Value)
79 {
80 return CommonTypes.Encode(Value);
81 }
82
90 {
91 if (this.HasPresetValue)
92 return this;
93 else
94 return new FloatAttribute(this.Name, this.Expression, ForDocument);
95 }
96
97 }
98}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:594
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Definition: CommonTypes.cs:46
Contains a 2D layout document.
Manages an attribute value or expression.
Definition: Attribute.cs:14
bool HasPresetValue
If the attribute has a preset value.
Definition: Attribute.cs:129
FloatAttribute(XmlElement E, string AttributeName, Layout2DDocument Document)
Floating point (Single) attribute
override string ToString(float Value)
Converts a value to a string.
override bool TryConvert(object Result, out float Value)
Tries to convert script result to a value of type float.
FloatAttribute(string AttributeName, float Value, Layout2DDocument Document)
Floating point (Single) attribute
override bool TryParse(string StringValue, out float Value)
Tries to parse a string value
FloatAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
FloatAttribute(string AttributeName, Expression Expression, Layout2DDocument Document)
Floating point (Single) attribute
Class managing a script expression.
Definition: Expression.cs:39