forked from PeterWaher/IoTGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariable.cs
More file actions
122 lines (108 loc) · 2.74 KB
/
Variable.cs
File metadata and controls
122 lines (108 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Text;
using Waher.Script.Abstraction.Elements;
using Waher.Script.Abstraction.Sets;
using Waher.Script.Objects;
namespace Waher.Script
{
/// <summary>
/// Contains information about a variable.
/// </summary>
public class Variable
{
private readonly string name;
private IElement value;
/// <summary>
/// Contains information about a variable.
/// </summary>
/// <param name="Name">Name of variable.</param>
/// <param name="Value">Value of variable.</param>
public Variable(string Name, IElement Value)
{
this.name = Name;
this.value = Value;
}
/// <summary>
/// Contains information about a variable.
/// </summary>
/// <param name="Name">Name of variable.</param>
/// <param name="Value">Value of variable.</param>
public Variable(string Name, double Value)
: this(Name, new DoubleNumber(Value))
{
}
/// <summary>
/// Contains information about a variable.
/// </summary>
/// <param name="Name">Name of variable.</param>
/// <param name="Value">Value of variable.</param>
public Variable(string Name, string Value)
: this(Name, new StringValue(Value))
{
}
/// <summary>
/// Contains information about a variable.
/// </summary>
/// <param name="Name">Name of variable.</param>
/// <param name="Value">Value of variable.</param>
public Variable(string Name, bool Value)
: this(Name, new BooleanValue(Value))
{
}
/// <summary>
/// Contains information about a variable.
/// </summary>
/// <param name="Name">Name of variable.</param>
/// <param name="Value">Value of variable.</param>
public Variable(string Name, object Value)
{
this.name = Name;
this.SetValue(Value);
}
/// <summary>
/// Sets the value of the variable.
/// </summary>
/// <param name="Value">Value of variable.</param>
internal void SetValue(object Value)
{
this.value = Expression.Encapsulate(Value);
}
/// <summary>
/// Name of variable.
/// </summary>
public string Name
{
get { return this.name; }
}
/// <summary>
/// Value element of variable.
/// </summary>
public IElement ValueElement
{
get { return this.value; }
}
/// <summary>
/// Object Value of variable.
/// </summary>
public object ValueObject
{
get { return this.value.AssociatedObjectValue; }
}
/// <summary>
/// <see cref="Object.ToString()"/>
/// </summary>
public override string ToString()
{
if (this.value is ObjectValue v)
{
object Obj = v.Value;
if (Obj == this)
return this.name + "=self";
else if (Obj is Variable Var)
return this.name + "=" + Var.name;
}
return this.name + "=" + this.value.ToString();
}
}
}