Skip to content

Commit f7e6dcf

Browse files
author
zzzprojects
committed
docs2
docs2
1 parent 9370f52 commit f7e6dcf

Some content is hidden

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

71 files changed

+10739
-0
lines changed

docs2/_data/pages.csv

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
title,url,category
2+
Overview,overview,tutorials
3+
Requirements,requirements,tutorials
4+
Installing,installing,tutorials
5+
Upgrading,upgrading,tutorials
6+
Licensing,licensing,tutorials
7+
Compile & Execute,tutorial-compile-execute,tutorials
8+
LINQ Dynamic,tutorial-linq-dynamic,tutorials
9+
API,api,api
10+
Eval.Execute,eval-execute,api
11+
Eval.Compile,eval-compile,api
12+
LINQ Dynamic,linq-dynamic,api
13+
String Extensions,string-extensions,api
14+
Compile & Execute,compile-execute,api
15+
Register & Unregister,register-unregister,api
16+
Options,options,api
17+
Eval Manager,eval-manager,api
18+
Where,linq-dynamic-where-examples,linq
19+
Select,linq-dynamic-select-examples,linq
20+
SelectMany,linq-dynamic-selectmany-examples,linq
21+
Take,linq-dynamic-take-examples,linq
22+
Skip,linq-dynamic-skip-examples,linq
23+
TakeWhile,linq-dynamic-takewhile-examples,linq
24+
SkipWhile,linq-dynamic-skipwhile-examples,linq
25+
OrderBy,linq-dynamic-orderby-examples,linq
26+
OrderByDescending,linq-dynamic-orderbydescending-examples,linq
27+
ThenBy,linq-dynamic-thenby-examples,linq
28+
ThenByDescending,linq-dynamic-thenbydescending-examples,linq
29+
Reverse,linq-dynamic-reverse-examples,linq
30+
GroupBy,linq-dynamic-groupby-examples,linq
31+
Distinct,linq-dynamic-distinct-examples,linq
32+
Union,linq-dynamic-union-examples,linq
33+
Intersect,linq-dynamic-intersect-examples,linq
34+
Except,linq-dynamic-except-examples,linq
35+
ToArray,linq-dynamic-toarray-examples,linq
36+
ToList,linq-dynamic-tolist-examples,linq
37+
ToDictionary,linq-dynamic-todictionary-examples,linq
38+
OfType,linq-dynamic-oftype-examples,linq
39+
First,linq-dynamic-first-examples,linq
40+
First,linq-dynamic-firstordefault-examples,linq
41+
ElementAt,linq-dynamic-elementat-examples,linq
42+
Range,linq-dynamic-range-examples,linq
43+
Repeat,linq-dynamic-repeat-examples,linq
44+
Any,linq-dynamic-any-examples,linq
45+
All,linq-dynamic-all-examples,linq
46+
Count,linq-dynamic-count-examples,linq
47+
Sum,linq-dynamic-sum-examples,linq
48+
Min,linq-dynamic-min-examples,linq
49+
Max,linq-dynamic-max-examples,linq
50+
Average,linq-dynamic-average-examples,linq
51+
Aggregate,linq-dynamic-aggregate-examples,linq
52+
Concat,linq-dynamic-concat-examples,linq
53+
EqualAll,linq-dynamic-equalall-examples,linq
54+
Combine,linq-dynamic-combine-examples,linq
55+
Articles,articles,articles
56+
FAQ,faq,faq
57+
Contact Us,contact-us,faq
58+
Issue Tracker,issue-tracker,faq
59+
General,faq-general,faq
60+
Installation,faq-installation,faq
61+
License,faq-license,faq
62+
Troubleshooting,troubleshooting,troubleshooting
63+
Trial Period Expired,trial-period-expired-exception,troubleshooting
64+
MD5,md5-exception,troubleshooting
65+
Eval-Expression.NET,/,home
66+
Trial, trial, trial

docs2/pages/api/api.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
layout: default
3+
title: API
4+
permalink: api
5+
---
6+
7+
{% include template-h1.html %}
8+
9+
## API
10+
11+
<ul>
12+
{% for num in (0..site.data.pages.size) %}
13+
{% if site.data.pages[num].category == page.permalink and site.data.pages[num].url != page.permalink %}
14+
<li><a href="{{ site.data.pages[num].url }}">{{ site.data.pages[num].title }}</a></li>
15+
{% endif %}
16+
{% endfor %}
17+
</ul>

docs2/pages/api/compile-execute.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
layout: default
3+
title: Compile & Execute
4+
description: Compile and execute a C# expression at runtime.
5+
permalink: compile-execute
6+
---
7+
8+
{% include template-h1.html %}
9+
10+
## Description
11+
{{ page.description }}
12+
13+
## Execute
14+
Execute a C# expression and return the result:
15+
16+
- Execute&lt;TResult&gt;(string code)
17+
- Execute&lt;TResult&gt;(string code, object parameters)
18+
- Execute&lt;TResult&gt;(string code, params object[] parameters)
19+
- Execute(string code)
20+
- Execute(string code, object parameters)
21+
- Execute(string code, params object[] parameters)
22+
23+
### Example
24+
{% highlight csharp %}
25+
// using Z.Expressions; // Don't forget to include this.
26+
27+
var context = new EvalContext();
28+
// ... context options ...
29+
30+
string code = "Price * Quantity";
31+
var price = context.Execute<decimal>(code, orderItem);
32+
{% endhighlight %}
33+
{% include component-try-it.html href='https://dotnetfiddle.net/tzBdMI' %}
34+
35+
## Compile
36+
Compile a C# expression and return a delegate:
37+
38+
- Compile&lt;TDelegate&gt;(string code)
39+
- Compile&lt;TDelegate&gt;(string code, IEnumerable&lt;string&gt; parameterNames)
40+
- Compile&lt;TDelegate&gt;(string code, params string[] parameterNames)
41+
- Compile(string): **Func&lt;object&gt;**
42+
- Compile(string, Type type1): **Func&lt;object, object&gt;**
43+
- Compile(string, Type type1, ... , Type type9): **Func&lt;object, ... , object, object&gt;**
44+
- Compile(string, IEnumerable&lt;Type&gt;): **Func&lt;IEnumerable, object&gt;**
45+
- Compile(string, params Type[]): **Func&lt;IEnumerable, object&gt;**
46+
- Compile(string, IDictionary&lt;string, Type&gt;): **Func&lt;IDictionary, object&gt;**
47+
48+
### Example
49+
{% highlight csharp %}
50+
// using Z.Expressions; // Don't forget to include this.
51+
52+
var context = new EvalContext();
53+
// ... context options ...
54+
55+
string code = "Price * Quantity";
56+
var compiled = context.Compile<Func<OrderItem, decimal>>(code);
57+
58+
decimal totals = 0;
59+
foreach(var item in list)
60+
{
61+
totals += compiled(item);
62+
}
63+
{% endhighlight %}
64+
{% include component-try-it.html href='https://dotnetfiddle.net/00YSGK' %}

docs2/pages/api/eval-compile.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
layout: default
3+
title: Eval.Compile
4+
description: Compile a C# expression and return a delegate.
5+
permalink: eval-compile
6+
---
7+
8+
{% include template-h1.html %}
9+
10+
## Description
11+
{{ page.description }}
12+
13+
Under the hood, the expression is parsed into tokens and then transformed into syntax node before being compiled using Expression Tree.
14+
15+
## Compile and return a strongly typed delegate
16+
You can return the delegate as a strongly typed function or action:
17+
18+
- Eval.Compile&lt;TDelegate&gt;(string code)
19+
- Eval.Compile&lt;TDelegate&gt;(string code, IEnumerable&lt;string&gt; parameterNames)
20+
- Eval.Compile&lt;TDelegate&gt;(string code, params string[] parameterNames)
21+
22+
### Example
23+
{% highlight csharp %}
24+
// Delegate Func
25+
var compiled = Eval.Compile<Func<int, int, int>>("{0} + {1}");
26+
int result = compiled(1, 2);
27+
28+
// Delegate Action
29+
var compiled = Eval.Compile<Action<int, int>>("{0} + {1}");
30+
compiled(1, 2);
31+
32+
// Named Parameter
33+
var compiled = Eval.Compile<Func<int, int, int>>("X + Y", "X", "Y");
34+
int result = compiled(1, 2);
35+
{% endhighlight %}
36+
{% include component-try-it.html href='https://dotnetfiddle.net/MBHlX8' %}
37+
38+
## Compile and return a delegate
39+
You can return the delegate as a generic delegate:
40+
41+
- Eval.Compile(string code): Func&lt;object&gt;
42+
- Eval.Compile(string code, Type type1): Func&lt;object, object&gt;
43+
- Eval.Compile(string code, Type type1, ... , Type type9): Func&lt;object, ... , object, object&gt;
44+
- Eval.Compile(string code, IEnumerable&lt;Type&gt; types): Func&lt;IEnumerable, object&gt;
45+
- Eval.Compile(string code, params Type[] types): Func&lt;IEnumerable, object&gt;
46+
- Eval.Compile(string code, IDictionary&lt;string, Type&gt; nameTypes): Func&lt;IDictionary, object&gt;
47+
48+
### Example
49+
{% highlight csharp %}
50+
// Overload: Up to 9 parameters can be used
51+
var compiled = Eval.Compile("{0} + {1}", typeof(int), typeof(int));
52+
object result = compiled(1, 2);
53+
54+
// Overload: params Type[]
55+
var values = new List<int>() {1, 2};
56+
var types = values.Select(x => x.GetType()).ToArray();
57+
58+
var compiled = Eval.Compile("{0} + {1}", types);
59+
var result = compiled(values);
60+
61+
// Overload: IDictionary<string, Type>
62+
var values = new Dictionary<string, object> { {"X", 1}, {"Y", 2} };
63+
var types = values.ToDictionary(x => x.Key, x => x.Value.GetType());
64+
65+
var compiled = Eval.Compile("X + Y", types);
66+
var result = compiled(values);
67+
{% endhighlight %}
68+
{% include component-try-it.html href='https://dotnetfiddle.net/870F71' %}
69+
70+

docs2/pages/api/eval-execute.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
layout: default
3+
title: Eval.Execute
4+
description: Execute a C# expression and return the result.
5+
permalink: eval-execute
6+
---
7+
8+
{% include template-h1.html %}
9+
10+
## Description
11+
{{ page.description }}
12+
13+
You can specify parameter value to use in the expression from various way:
14+
15+
- Anonymous Type
16+
- Argument Position
17+
- Class Member
18+
- Dictionary
19+
20+
Under the hood, the fist time an expression is executed, it's getting compiled and the delegate is stored in the memory before being returned and executed. All future call from the same expression will retrieve the delegate from the memory to optimize the performance.
21+
22+
Even with this optimization, if you have to evaluate multiple times the same expression, by example in a for loop, we highly recommend you to use directly the delegate returning from the Compile method instead.
23+
24+
## Execute and return a strongly typed result
25+
You can return the result as a strongly typed type:
26+
27+
- Eval.Execute&lt;TResult&gt;(string code)
28+
- Eval.Execute&lt;TResult&gt;(string code, object parameters)
29+
- Eval.Execute&lt;TResult&gt;(string code, params object[] parameters)
30+
31+
### Example
32+
33+
{% highlight csharp %}
34+
// Parameter: Anonymous Type
35+
int result = Eval.Execute<int>("X + Y", new { X = 1, Y = 2} );
36+
37+
// Parameter: Argument Position
38+
int result = Eval.Execute<int>("{0} + {1}", 1, 2);
39+
40+
// Parameter: Class Member
41+
dynamic expandoObject = new ExpandoObject();
42+
expandoObject.X = 1;
43+
expandoObject.Y = 2;
44+
int result = Eval.Execute<int>("X + Y", expandoObject);
45+
46+
// Parameter: Dictionary Key
47+
var values = new Dictionary<string, object>() { {"X", 1}, {"Y", 2} };
48+
int result = Eval.Execute<int>("X + Y", values);
49+
{% endhighlight %}
50+
{% include component-try-it.html href='https://dotnetfiddle.net/W9TwcP' %}
51+
52+
## Execute and return an object result
53+
You can return the result as an object:
54+
55+
- Eval.Execute(string code)
56+
- Eval.Execute(string code, object parameters)
57+
- Eval.Execute(string code, params object[] parameters)
58+
59+
{% highlight csharp %}
60+
// Parameter: Anonymous Type
61+
object result = Eval.Execute("X + Y", new { X = 1, Y = 2} );
62+
63+
// Parameter: Argument Position
64+
object result = Eval.Execute("{0} + {1}", 1, 2);
65+
66+
// Parameter: Class Member
67+
dynamic expandoObject = new ExpandoObject();
68+
expandoObject.X = 1;
69+
expandoObject.Y = 2;
70+
object result = Eval.Execute("X + Y", expandoObject);
71+
72+
// Parameter: Dictionary Key
73+
var values = new Dictionary<string, object>() { {"X", 1}, {"Y", 2} };
74+
object result = Eval.Execute("X + Y", values);
75+
{% endhighlight %}
76+
{% include component-try-it.html href='https://dotnetfiddle.net/8mtLH8' %}

docs2/pages/api/eval-manager.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
layout: default
3+
title: Eval Manager
4+
description: Static manager class for options shared between all instances.
5+
permalink: eval-manager
6+
---
7+
8+
{% include template-h1.html %}
9+
10+
## Description
11+
{{ page.description }}
12+
13+
## Cache
14+
Gets or sets the cache to use to cache compiled delegate.
15+
16+
### Example
17+
{% highlight csharp %}
18+
// using Z.Expressions; // Don't forget to include this.
19+
EvalManager.Cache = MemoryCache.Default;
20+
{% endhighlight %}
21+
22+
> You can use your own cache provider inheriting from System.Runtime.Caching.ObjectCache
23+
24+
## DefaultContext
25+
Gets or sets the default context to use for all operations using the default context.
26+
27+
You can also directly change options
28+
- [Register & Unregister](register-unregister)
29+
- [Options](options)
30+
31+
The default context is used in static methods:
32+
- [Eval.Execute](eval-execute)
33+
- [Eval.Compile](eval-compile)
34+
- [LINQ Dynamic](linq-dynamic)
35+
- [string".Execute](string-extensions#stringexecute)
36+
- [string".Compile](string-extensions#stringcompile)
37+
38+
### Example
39+
{% highlight csharp %}
40+
// using Z.Expressions; // Don't forget to include this.
41+
EvalManager.DefaultContext.RegisterExtensionMethod(typeof(Z.ExtensionMethods))
42+
43+
// Make member case insensitive (Math.pOW = Math.Pow)
44+
EvalManager.DefaultContext.BindingFlags = BindingFlags.IgnoreCase | context.BindingFlags
45+
{% endhighlight %}
46+
47+

0 commit comments

Comments
 (0)