-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathDCConstExpressionItem.cs
More file actions
169 lines (161 loc) · 4.55 KB
/
DCConstExpressionItem.cs
File metadata and controls
169 lines (161 loc) · 4.55 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
都昌数值表达式引擎 DCSoft.Expression
南京都昌信息科技有限公司 2018年 版权所有
公司网址 http://www.dcwriter.cn
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace DCSoft.Expression
{
/// <summary>
/// 常量表达式元素。
/// </summary>
[System.Runtime.InteropServices.ComVisible( false )]
public class DCConstExpressionItem : DCExpressionItem
{
public DCConstExpressionItem()
{
}
/// <summary>
/// 初始化对象
/// </summary>
/// <param name="v">数值</param>
/// <param name="vt">数据类型</param>
public DCConstExpressionItem(object v, DCValueType vt)
{
this._ValueType = vt;
if (vt == DCValueType.String)
{
this._StringValue = (string)v;
}
else if (vt == DCValueType.Number)
{
this._NumberValue = (double)v;
}
else if (vt == DCValueType.Boolean)
{
this._BooleanValue = (bool)v;
}
}
private string _StringValue = null;
/// <summary>
/// 字符串数值
/// </summary>
public string StringValue
{
get
{
return _StringValue;
}
set
{
_StringValue = value;
}
}
private bool _BooleanValue = false;
/// <summary>
/// 布尔值数值
/// </summary>
public bool BooleanValue
{
get
{
return _BooleanValue;
}
set
{
_BooleanValue = value;
}
}
private double _NumberValue = 0;
/// <summary>
/// 数字数值
/// </summary>
public double NumberValue
{
get
{
return _NumberValue;
}
set
{
_NumberValue = value;
}
}
private DCValueType _ValueType = DCValueType.String;
/// <summary>
/// 数据类型
/// </summary>
public DCValueType ValueType
{
get
{
return _ValueType;
}
set
{
_ValueType = value;
}
}
/// <summary>
/// 执行表达式
/// </summary>
/// <param name="context">上下文对象</param>
/// <returns>执行结果</returns>
public override object Eval(IDCExpressionContext context)
{
if (this.ValueType == DCValueType.String)
{
return this._StringValue;
}
if (this.ValueType == DCValueType.Number)
{
return this._NumberValue;
}
if (this.ValueType == DCValueType.Boolean)
{
return this._BooleanValue;
}
throw new NotSupportedException(this.ValueType.ToString());
}
/// <summary>
/// 调试输出文本
/// </summary>
/// <param name="indentLevel"></param>
/// <param name="str"></param>
public override void ToDebugString(int indentLevel, StringBuilder str)
{
string txt = new string(' ', indentLevel * 3);
if (this.ValueType == DCValueType.Number)
{
txt = txt + "Number:" + this.NumberValue;
}
else if (this.ValueType == DCValueType.String)
{
txt = txt + "String:" + this.StringValue;
}
else
{
txt = txt + "Boolean:" + this.BooleanValue;
}
str.AppendLine(txt);
}
public override string ToString()
{
if (this.ValueType == DCValueType.Number)
{
return "Number:" + this.NumberValue;
}
else if (this.ValueType == DCValueType.String)
{
return "String:" + this.StringValue;
}
else if (this.ValueType == DCValueType.Boolean)
{
return "Boolean:" + this.BooleanValue;
}
return this.ValueType.ToString();
}
}
}