Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SByte.cs
1using System;
2using System.IO;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Script;
6
8{
13 {
14 private System.SByte? value;
15 private Expression script;
16
23 : base(Parent, Model)
24 {
25 }
26
30 public override string LocalName => nameof(SByte);
31
39 {
40 return new SByte(Parent, Model);
41 }
42
47 public override Task FromXml(XmlElement Definition)
48 {
49 if (System.SByte.TryParse(Definition.InnerText, out System.SByte Value))
50 {
51 this.value = Value;
52 this.script = null;
53 }
54 else
55 {
56 this.value = null;
57 this.script = new Expression(Definition.InnerText);
58 }
59
60 return Task.CompletedTask;
61 }
62
68 public async Task Append(MemoryStream Output, Variables Variables)
69 {
70 object Result;
71
72 Output.WriteByte(this.value.HasValue ? (byte)this.value.Value :
73 (Result = await this.script.EvaluateAsync(Variables)) is System.SByte Value ? (byte)Value :
74 (byte)Convert.ToSByte(Result));
75 }
76 }
77}
Root node of a simulation model
Definition: Model.cs:49
Abstract base class for simulation nodes
ISimulationNode Parent
Parent node in the simulation model.
override string LocalName
Local name of Binary element defining contents of class.
Definition: SByte.cs:30
async Task Append(MemoryStream Output, Variables Variables)
Appends the binary element to the output stream.
Definition: SByte.cs:68
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
Definition: SByte.cs:38
SByte(ISimulationNode Parent, Model Model)
SByte value.
Definition: SByte.cs:22
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with Binary definition.
Definition: SByte.cs:47
Abstract base class for values
Definition: Value.cs:11
Class managing a script expression.
Definition: Expression.cs:39
Collection of variables.
Definition: Variables.cs:25
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...