-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathDCFunctionExpressionItem.cs
More file actions
136 lines (128 loc) · 3.71 KB
/
DCFunctionExpressionItem.cs
File metadata and controls
136 lines (128 loc) · 3.71 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
/*
都昌数值表达式引擎 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 DCFunctionExpressionItem : DCExpressionItem
{
public DCFunctionExpressionItem()
{
}
private string _Name = null;
/// <summary>
/// 名称
/// </summary>
public string Name
{
get
{
return _Name;
}
set
{
_Name = value;
}
}
private DCExpressoinItemList _Parameters = new DCExpressoinItemList();
/// <summary>
/// 参数列表
/// </summary>
public DCExpressoinItemList Parameters
{
get
{
return _Parameters;
}
set
{
_Parameters = value;
}
}
/// <summary>
/// 执行表达式
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override object Eval(IDCExpressionContext context)
{
object[] pvs = null;
if (_Parameters != null && _Parameters.Count > 0)
{
pvs = new object[this._Parameters.Count];
for (int iCount = 0; iCount < this._Parameters.Count; iCount++)
{
pvs[iCount] = this._Parameters[iCount].Eval(context);
}
}
object result = context.ExecuteFunction(this.Name, pvs);
return result;
}
internal override void AddSubItem(DCExpressionItem item)
{
if (_Parameters == null)
{
_Parameters = new DCExpressoinItemList();
}
_Parameters.Add(item);
}
public override DCExpressionItem Clone()
{
DCFunctionExpressionItem item = (DCFunctionExpressionItem)this.MemberwiseClone();
if (this._Parameters != null)
{
item._Parameters = this._Parameters.CloneDeeply();
}
return item;
}
public override void ToDebugString(int indentLevel, StringBuilder str)
{
string preFix = new string(' ', indentLevel * 3);
if (this.Parameters != null && this.Parameters.Count > 0)
{
str.AppendLine(preFix + "function " + this.Name);
str.AppendLine(preFix + "(");
foreach (var item in this.Parameters)
{
item.ToDebugString(indentLevel + 1, str);
}
str.AppendLine(preFix + ")");
}
else
{
str.AppendLine(preFix + this.Name + "( )");
}
}
public override string ToString()
{
return "function " + this.Name + "( )";
}
}
/// <summary>
/// 函数类型
/// </summary>
[System.Runtime.InteropServices.ComVisible(false)]
public enum DCFunctionType
{
/// <summary>
/// 字符串函数
/// </summary>
String,
/// <summary>
/// 数值函数
/// </summary>
Number,
/// <summary>
/// 聚合函数
/// </summary>
Group
}
}