Skip to content

Commit 53794ff

Browse files
author
zzzprojects
committed
ADD Eval.Execute && Eval.Compile + Improve Performance
ADD Eval.Execute && Eval.Compile + Improve Performance
1 parent 9eb1b03 commit 53794ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2108
-82
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime.
2+
// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET
3+
// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues
4+
// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE
5+
// More projects: http://www.zzzprojects.com/
6+
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
7+
8+
using System;
9+
using System.Collections;
10+
using System.Collections.Generic;
11+
12+
namespace Z.Expressions
13+
{
14+
public static partial class Eval
15+
{
16+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
17+
/// <param name="code">The code or expression to compile.</param>
18+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
19+
public static Func<object> Compile(string code)
20+
{
21+
return EvalManager.DefaultContext.Compile(code);
22+
}
23+
24+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
25+
/// <param name="code">The code or expression to compile.</param>
26+
/// <param name="parameterTypes">Parameter types used to compile the code or expression.</param>
27+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
28+
public static Func<IEnumerable, object> Compile(string code, IEnumerable<Type> parameterTypes)
29+
{
30+
return EvalManager.DefaultContext.Compile(code, parameterTypes);
31+
}
32+
33+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
34+
/// <param name="code">The code or expression to compile.</param>
35+
/// <param name="parameterTypes">Parameter types used to compile the code or expression.</param>
36+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
37+
public static Func<IEnumerable, object> Compile(string code, params Type[] parameterTypes)
38+
{
39+
return EvalManager.DefaultContext.Compile(code, parameterTypes);
40+
}
41+
42+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
43+
/// <param name="code">The code or expression to compile.</param>
44+
/// <param name="parameterTypes">Parameter types used to compile the code or expression.</param>
45+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
46+
public static Func<IDictionary, object> Compile(string code, IDictionary<string, Type> parameterTypes)
47+
{
48+
return EvalManager.DefaultContext.Compile(code, parameterTypes);
49+
}
50+
51+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
52+
/// <param name="code">The code or expression to compile.</param>
53+
/// <param name="type1">The first type used to compile the code or expression.</param>
54+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
55+
public static Func<object, object> Compile(string code, Type type1)
56+
{
57+
return EvalManager.DefaultContext.Compile(code, type1);
58+
}
59+
60+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
61+
/// <param name="code">The code or expression to compile.</param>
62+
/// <param name="type1">The first type used to compile the code or expression.</param>
63+
/// <param name="type2">The second type used to compile the code or expression.</param>
64+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
65+
public static Func<object, object, object> Compile(string code, Type type1, Type type2)
66+
{
67+
return EvalManager.DefaultContext.Compile(code, type1, type2);
68+
}
69+
70+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
71+
/// <param name="code">The code or expression to compile.</param>
72+
/// <param name="type1">The first type used to compile the code or expression.</param>
73+
/// <param name="type2">The second type used to compile the code or expression.</param>
74+
/// <param name="type3">The third type used to compile the code or expression.</param>
75+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
76+
public static Func<object, object, object, object> Compile(string code, Type type1, Type type2, Type type3)
77+
{
78+
return EvalManager.DefaultContext.Compile(code, type1, type2, type3);
79+
}
80+
81+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
82+
/// <param name="code">The code or expression to compile.</param>
83+
/// <param name="type1">The first type used to compile the code or expression.</param>
84+
/// <param name="type2">The second type used to compile the code or expression.</param>
85+
/// <param name="type3">The third type used to compile the code or expression.</param>
86+
/// <param name="type4">The fourth type used to compile the code or expression.</param>
87+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
88+
public static Func<object, object, object, object, object> Compile(string code, Type type1, Type type2, Type type3, Type type4)
89+
{
90+
return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4);
91+
}
92+
93+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
94+
/// <param name="code">The code or expression to compile.</param>
95+
/// <param name="type1">The first type used to compile the code or expression.</param>
96+
/// <param name="type2">The second type used to compile the code or expression.</param>
97+
/// <param name="type3">The third type used to compile the code or expression.</param>
98+
/// <param name="type4">The fourth type used to compile the code or expression.</param>
99+
/// <param name="type5">The fifth type used to compile the code or expression.</param>
100+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
101+
public static Func<object, object, object, object, object, object> Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5)
102+
{
103+
return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4, type5);
104+
}
105+
106+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
107+
/// <param name="code">The code or expression to compile.</param>
108+
/// <param name="type1">The first type used to compile the code or expression.</param>
109+
/// <param name="type2">The second type used to compile the code or expression.</param>
110+
/// <param name="type3">The third type used to compile the code or expression.</param>
111+
/// <param name="type4">The fourth type used to compile the code or expression.</param>
112+
/// <param name="type5">The fifth type used to compile the code or expression.</param>
113+
/// <param name="type6">The sixth type used to compile the code or expression.</param>
114+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
115+
public static Func<object, object, object, object, object, object, object> Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6)
116+
{
117+
return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4, type5, type6);
118+
}
119+
120+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
121+
/// <param name="code">The code or expression to compile.</param>
122+
/// <param name="type1">The first type used to compile the code or expression.</param>
123+
/// <param name="type2">The second type used to compile the code or expression.</param>
124+
/// <param name="type3">The third type used to compile the code or expression.</param>
125+
/// <param name="type4">The fourth type used to compile the code or expression.</param>
126+
/// <param name="type5">The fifth type used to compile the code or expression.</param>
127+
/// <param name="type6">The sixth type used to compile the code or expression.</param>
128+
/// <param name="type7">The seventh type used to compile the code or expression.</param>
129+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
130+
public static Func<object, object, object, object, object, object, object, object> Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7)
131+
{
132+
return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4, type5, type6, type7);
133+
}
134+
135+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
136+
/// <param name="code">The code or expression to compile.</param>
137+
/// <param name="type1">The first type used to compile the code or expression.</param>
138+
/// <param name="type2">The second type used to compile the code or expression.</param>
139+
/// <param name="type3">The third type used to compile the code or expression.</param>
140+
/// <param name="type4">The fourth type used to compile the code or expression.</param>
141+
/// <param name="type5">The fifth type used to compile the code or expression.</param>
142+
/// <param name="type6">The sixth type used to compile the code or expression.</param>
143+
/// <param name="type7">The seventh type used to compile the code or expression.</param>
144+
/// <param name="type8">The eighth type used to compile the code or expression.</param>
145+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
146+
public static Func<object, object, object, object, object, object, object, object, object> Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7, Type type8)
147+
{
148+
return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4, type5, type6, type7, type8);
149+
}
150+
151+
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary>
152+
/// <param name="code">The code or expression to compile.</param>
153+
/// <param name="type1">The first type used to compile the code or expression.</param>
154+
/// <param name="type2">The second type used to compile the code or expression.</param>
155+
/// <param name="type3">The third type used to compile the code or expression.</param>
156+
/// <param name="type4">The fourth type used to compile the code or expression.</param>
157+
/// <param name="type5">The fifth type used to compile the code or expression.</param>
158+
/// <param name="type6">The sixth type used to compile the code or expression.</param>
159+
/// <param name="type7">The seventh type used to compile the code or expression.</param>
160+
/// <param name="type8">The eighth type used to compile the code or expression.</param>
161+
/// <param name="type9">The ninth type used to compile the code or expression.</param>
162+
/// <returns>A delegate of type Func that represents the compiled code or expression.</returns>
163+
public static Func<object, object, object, object, object, object, object, object, object, object> Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7, Type type8, Type type9)
164+
{
165+
return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4, type5, type6, type7, type8, type9);
166+
}
167+
}
168+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime.
2+
// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET
3+
// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues
4+
// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE
5+
// More projects: http://www.zzzprojects.com/
6+
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
7+
8+
using System.Collections.Generic;
9+
10+
namespace Z.Expressions
11+
{
12+
public static partial class Eval
13+
{
14+
/// <summary>Compile the code or expression and return a TDelegate of type Func or Action to execute.</summary>
15+
/// <typeparam name="TDelegate">Type of the delegate (Func or Action) to use to compile the code or expression.</typeparam>
16+
/// <param name="code">The code or expression to compile.</param>
17+
/// <returns>A TDelegate of type Func or Action that represents the compiled code or expression.</returns>
18+
public static TDelegate Compile<TDelegate>(string code)
19+
{
20+
return EvalManager.DefaultContext.Compile<TDelegate>(code);
21+
}
22+
23+
/// <summary>Compile the code or expression and return a TDelegate of type Func or action to execute.</summary>
24+
/// <typeparam name="TDelegate">Type of the delegate (Func or Action) to use to compile the code or expression.</typeparam>
25+
/// <param name="code">The code or expression to compile.</param>
26+
/// <param name="parameterNames">Parameter names used to compile the code or expressions.</param>
27+
/// <returns>A TDelegate of type Func or Action that represents the compiled code or expression.</returns>
28+
public static TDelegate Compile<TDelegate>(string code, IEnumerable<string> parameterNames)
29+
{
30+
return EvalManager.DefaultContext.Compile<TDelegate>(code, parameterNames);
31+
}
32+
33+
/// <summary>Compile the code or expression and return a TDelegate of type Func or Action to execute.</summary>
34+
/// <typeparam name="TDelegate">Type of the delegate (Func or Action) to use to compile the code or expression.</typeparam>
35+
/// <param name="code">The code or expression to compile.</param>
36+
/// <param name="parameterNames">Parameter names used to compile the code or expressions.</param>
37+
/// <returns>A TDelegate of type Func or Action that represents the compiled code or expression.</returns>
38+
public static TDelegate Compile<TDelegate>(string code, params string[] parameterNames)
39+
{
40+
return EvalManager.DefaultContext.Compile<TDelegate>(code, parameterNames);
41+
}
42+
}
43+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime.
2+
// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET
3+
// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues
4+
// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE
5+
// More projects: http://www.zzzprojects.com/
6+
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
7+
8+
namespace Z.Expressions
9+
{
10+
public static partial class Eval
11+
{
12+
/// <summary>Compile and evaluate the code or expression and return the result.</summary>
13+
/// <param name="code">The code or expression to evaluate.</param>
14+
/// <returns>The evaluated result or null that represents the evaluted code or expression.</returns>
15+
public static object Execute(string code)
16+
{
17+
return EvalManager.DefaultContext.Execute(code);
18+
}
19+
20+
/// <summary>Compile and evaluate the code or expression and return the result.</summary>
21+
/// <param name="code">The code or expression to evaluate.</param>
22+
/// <param name="parameters">The parameter values used to evaluates the code or expression.</param>
23+
/// <returns>The evaluated result or null that represents the evaluted code or expression.</returns>
24+
public static object Execute(string code, object parameters)
25+
{
26+
return EvalManager.DefaultContext.Execute(code, parameters);
27+
}
28+
29+
/// <summary>Compile and evaluate the code or expression and return the result.</summary>
30+
/// <param name="code">The code or expression to evaluate.</param>
31+
/// <param name="parameters">The parameter values used to evaluates the code or expression.</param>
32+
/// <returns>The evaluated result or null that represents the evaluted code or expression.</returns>
33+
public static object Execute(string code, params object[] parameters)
34+
{
35+
return EvalManager.DefaultContext.Execute(code, parameters);
36+
}
37+
}
38+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime.
2+
// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET
3+
// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues
4+
// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE
5+
// More projects: http://www.zzzprojects.com/
6+
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
7+
8+
namespace Z.Expressions
9+
{
10+
public static partial class Eval
11+
{
12+
/// <summary>Compile and evaluate the code or expression and return the result of type TResult.</summary>
13+
/// <typeparam name="TResult">Type of the result of the evaluted code or expression.</typeparam>
14+
/// <param name="code">The code or expression to evaluate.</param>
15+
/// <returns>The evaluated result of type TResult or null that represents the evaluted code or expression.</returns>
16+
public static TResult Execute<TResult>(string code)
17+
{
18+
return EvalManager.DefaultContext.Execute<TResult>(code);
19+
}
20+
21+
/// <summary>Compile and evaluate the code or expression and return the result of type TResult.</summary>
22+
/// <typeparam name="TResult">Type of the result of the evaluted code or expression.</typeparam>
23+
/// <param name="code">The code or expression to evaluate.</param>
24+
/// <param name="parameters">The parameter values used to evaluates the code or expression.</param>
25+
/// <returns>The evaluated result of type TResult or null that represents the evaluted code or expression.</returns>
26+
public static TResult Execute<TResult>(string code, object parameters)
27+
{
28+
return EvalManager.DefaultContext.Execute<TResult>(code, parameters);
29+
}
30+
31+
/// <summary>Compile and evaluate the code or expression and return the result of type TResult.</summary>
32+
/// <typeparam name="TResult">Type of the result of the evaluted code or expression.</typeparam>
33+
/// <param name="code">The code or expression to evaluate.</param>
34+
/// <param name="parameters">The parameter values used to evaluates the code or expression.</param>
35+
/// <returns>The evaluated result of type TResult or null that represents the evaluted code or expression.</returns>
36+
public static TResult Execute<TResult>(string code, params object[] parameters)
37+
{
38+
return EvalManager.DefaultContext.Execute<TResult>(code, parameters);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)