-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interpreter.cs
100 lines (94 loc) · 3.59 KB
/
Interpreter.cs
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
using System.Collections;
namespace EasyExcelFramework
{
public class InterpreterClass
{
public bool Eval(EasyExcelF ee, string expression, dynamic[] parms)
{
DynamicExpresso.Interpreter DExpresso = new DynamicExpresso.Interpreter();
foreach (DictionaryEntry variable in ee.Environ)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
foreach (var variable in ee.Globals)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
foreach (var variable in ee.Locals)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
int paramno = 0;
foreach (string param in parms)
{
paramno++;
DExpresso.SetVariable("PARAM" + paramno, parms[paramno - 1]);
}
return (bool)DExpresso.Eval(expression);
}
public bool Eval(EasyExcelF ee, string expression)
{
DynamicExpresso.Interpreter DExpresso = new DynamicExpresso.Interpreter();
foreach (DictionaryEntry variable in ee.Environ)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
foreach (var variable in ee.Globals)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
foreach (var variable in ee.Locals)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
return (bool)DExpresso.Eval(expression);
}
public string EvalToString(EasyExcelF ee, string expression, dynamic[] parms)
{
DynamicExpresso.Interpreter DExpresso = new DynamicExpresso.Interpreter();
foreach (DictionaryEntry variable in ee.Environ)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
foreach (var variable in ee.Globals)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
foreach (var variable in ee.Locals)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
int paramno = 0;
foreach (string param in ee.passedparams)
{
paramno++;
DExpresso.SetVariable("PARAM" + paramno, param);
}
return (string)DExpresso.Eval(expression).ToString();
}
public dynamic DynamicEval(EasyExcelF ee, string expression, dynamic[] parms)
{
DynamicExpresso.Interpreter DExpresso = new DynamicExpresso.Interpreter();
foreach (DictionaryEntry variable in ee.Environ)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
foreach (var variable in ee.Globals)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
foreach (var variable in ee.Locals)
{
DExpresso.SetVariable(variable.Key.ToString(), variable.Value);
}
StringConverter sc=new StringConverter();
int paramno = 0;
foreach (string param in ee.passedparams)
{
paramno++;
DExpresso.SetVariable("PARAM" + paramno, sc.DetectType(param));
}
return DExpresso.Eval(expression);
}
}
}