Skip to content

Commit eeb2983

Browse files
Merge pull request #31 from Lempireqc/master
change for fiddle, not all check, need to all check when really all finish.
2 parents 806e401 + fd0082f commit eeb2983

20 files changed

+246
-464
lines changed

docs/CNAME

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
eval-expression.net
1+
eval-expression.net
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a href="{{ include.href }}">try it online</a>

docs/index.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ int result = Eval.Execute<int>(@"
219219
// - Anonymous Type
220220
// - Extension Methods
221221
// - Generic Type
222-
{% endhighlight %}
222+
{% endhighlight %}
223+
{% include component-try-it.html href='https://dotnetfiddle.net/MHoctF' %}
223224
</div>
224225
</div>
225226
</div>
@@ -251,6 +252,7 @@ int result = Eval.Execute<int>(@"
251252
var list = new List<int>() { 1, 2, 3, 4, 5 };
252253
return list.Where(x => x > X).Take(Y).Count();", new { X = 1, Y = 2});
253254
{% endhighlight %}
255+
{% include component-try-it.html href='https://dotnetfiddle.net/j3WHx1' %}
254256
</div>
255257
</div>
256258
</div>
@@ -304,6 +306,8 @@ int result = Eval.Execute<int>("X + Y", values);
304306
// Argument Position
305307
int result = Eval.Execute<int>("{0} + {1}", 1, 2);
306308
{% endhighlight %}
309+
{% include component-try-it.html href='https://dotnetfiddle.net/V6cZ0K' %}
310+
307311
</div>
308312
</div>
309313

@@ -326,6 +330,7 @@ int result = Eval.Execute<int>(@"
326330
var list = new List<int>() { 1, 2, 3, 4, 5 };
327331
return list.Where(x => x > X).Take(Y).Count();", new { X = 1, Y = 2});
328332
{% endhighlight %}
333+
{% include component-try-it.html href='https://dotnetfiddle.net/eZM4mh' %}
329334
</div>
330335
</div>
331336

@@ -350,6 +355,7 @@ var customer = new Customer() { Name = "ZZZ" };
350355
var nameGetter = Eval.Compile<Func<Customer, string>>("x.Name", "x");
351356
var name = nameGetter(customer);
352357
{% endhighlight %}
358+
{% include component-try-it.html href='https://dotnetfiddle.net/yW8S35' %}
353359
</div>
354360
</div>
355361

docs/pages/api/compile-execute.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var context = new EvalContext();
3030
string code = "Price * Quantity";
3131
var price = context.Execute<decimal>(code, orderItem);
3232
{% endhighlight %}
33+
{% include component-try-it.html href='https://dotnetfiddle.net/tzBdMI' %}
3334

3435
## Compile
3536
Compile a C# expression and return a delegate:
@@ -60,3 +61,4 @@ foreach(var item in list)
6061
totals += compiled(item);
6162
}
6263
{% endhighlight %}
64+
{% include component-try-it.html href='https://dotnetfiddle.net/00YSGK' %}

docs/pages/api/eval-compile.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ compiled(1, 2);
3333
var compiled = Eval.Compile<Func<int, int, int>>("X + Y", "X", "Y");
3434
int result = compiled(1, 2);
3535
{% endhighlight %}
36+
{% include component-try-it.html href='https://dotnetfiddle.net/MBHlX8' %}
3637

3738
## Compile and return a delegate
3839
You can return the delegate as a generic delegate:
@@ -64,5 +65,6 @@ var types = values.ToDictionary(x => x.Key, x => x.Value.GetType());
6465
var compiled = Eval.Compile("X + Y", types);
6566
var result = compiled(values);
6667
{% endhighlight %}
68+
{% include component-try-it.html href='https://dotnetfiddle.net/PY1TRM' %}
6769

6870

docs/pages/api/eval-execute.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ int result = Eval.Execute<int>("X + Y", expandoObject);
4747
var values = new Dictionary<string, object>() { {"X", 1}, {"Y", 2} };
4848
int result = Eval.Execute<int>("X + Y", values);
4949
{% endhighlight %}
50+
{% include component-try-it.html href='https://dotnetfiddle.net/W9TwcP' %}
5051

5152
## Execute and return an object result
5253
You can return the result as an object:
@@ -72,3 +73,4 @@ object result = Eval.Execute("X + Y", expandoObject);
7273
var values = new Dictionary<string, object>() { {"X", 1}, {"Y", 2} };
7374
object result = Eval.Execute("X + Y", values);
7475
{% endhighlight %}
76+
{% include component-try-it.html href='https://dotnetfiddle.net/8mtLH8' %}

docs/pages/api/linq-dynamic.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var list = new List<int>() { 1, 2, 3, 4, 5 };
4040
var list2 = list.Where(x => "x > 2");
4141
var list3 = list.Where(x => "x > X", new { X = 2 }); // with parameter
4242
{% endhighlight %}
43+
{% include component-try-it.html href='https://dotnetfiddle.net/S42mkU' %}
4344

4445
## LINQ Dynamic - Ordering and Selecting
4546
You can use any ordering and selecting method with a dynamic C# expression:

docs/pages/api/string-extensions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Execute a C# expression. Extend the String class.
3535
var result1 = "1+2".Execute<int>(); // return 3
3636
var result2 = "X+Y".Execute(new { X = 1, Y = 2 }); // return 3
3737
{% endhighlight %}
38+
{% include component-try-it.html href='https://dotnetfiddle.net/iXeE87' %}
39+
3840

3941
## "string".Compile
4042
Compile a C# expression. Extend the String class.

docs/pages/linq/aggregate.md

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,22 @@ This C# example uses the LINQ Aggregate method with a dynamic expression to crea
1818

1919
### LINQ
2020
{% highlight csharp %}
21-
private void uiAggregate_Simple_LINQ_Click(object sender, EventArgs e)
22-
{
23-
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};
21+
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};
2422

25-
var product = doubles.Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor);
23+
var product = doubles.Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor);
2624

27-
var sb = new StringBuilder();
28-
29-
sb.AppendLine("Total product of all numbers: {0}", product);
30-
31-
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
32-
}
25+
Console.WriteLine("Total product of all numbers: {0}", product);
3326
{% endhighlight %}
27+
{% include component-try-it.html href='https://dotnetfiddle.net/BZLbt5' %}
3428

3529
### LINQ Execute
3630
{% highlight csharp %}
37-
private void uiAggregate_Simple_LINQ_Execute_Click(object sender, EventArgs e)
38-
{
39-
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};
40-
41-
var product = doubles.Execute<double>("Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor)");
42-
43-
var sb = new StringBuilder();
31+
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};
4432

45-
sb.AppendLine("Total product of all numbers: {0}", product);
33+
var product = doubles.Execute<double>("Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor)");
4634

47-
My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
48-
}
35+
Console.WriteLine("Total product of all numbers: {0}", product);
36+
{% include component-try-it.html href='https://dotnetfiddle.net/HbOEOt' %}
4937
{% endhighlight %}
5038

5139
### Result
@@ -61,39 +49,28 @@ This C# example uses the LINQ Aggregate method with a dynamic expression to crea
6149

6250
### LINQ
6351
{% highlight csharp %}
64-
private void uiAggregate_Seed_LINQ_Click(object sender, EventArgs e)
65-
{
66-
var startBalance = 100.0;
52+
var startBalance = 100.0;
6753

68-
int[] attemptedWithdrawals = {20, 10, 40, 50, 10, 70, 30};
54+
int[] attemptedWithdrawals = {20, 10, 40, 50, 10, 70, 30};
6955

70-
var endBalance = attemptedWithdrawals.Aggregate(startBalance, (balance, nextWithdrawal) => nextWithdrawal <= balance ? balance - nextWithdrawal : balance);
56+
var endBalance = attemptedWithdrawals.Aggregate(startBalance, (balance, nextWithdrawal) => nextWithdrawal <= balance ? balance - nextWithdrawal : balance);
7157

72-
var sb = new StringBuilder();
73-
74-
sb.AppendLine("Ending balance: {0}", endBalance);
75-
76-
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
77-
}
58+
Console.WriteLine("Ending balance: {0}", endBalance);
7859
{% endhighlight %}
60+
{% include component-try-it.html href='https://dotnetfiddle.net/LqobT0' %}
7961

8062
### LINQ Execute
8163
{% highlight csharp %}
82-
private void uiAggregate_Seed_LINQ_Execute_Click(object sender, EventArgs e)
83-
{
84-
var startBalance = 100.0;
85-
86-
int[] attemptedWithdrawals = {20, 10, 40, 50, 10, 70, 30};
64+
var startBalance = 100.0;
8765

88-
var endBalance = attemptedWithdrawals.Execute<double>("Aggregate(startBalance, (balance, nextWithdrawal) => ((nextWithdrawal <= balance) ? (balance - nextWithdrawal) : balance)", new {startBalance});
66+
int[] attemptedWithdrawals = {20, 10, 40, 50, 10, 70, 30};
8967

90-
var sb = new StringBuilder();
68+
var endBalance = attemptedWithdrawals.Execute<double>("Aggregate(startBalance, (balance, nextWithdrawal) => ((nextWithdrawal <= balance) ? (balance - nextWithdrawal) : balance)", new {startBalance});
9169

92-
sb.AppendLine("Ending balance: {0}", endBalance);
70+
Console.WriteLine("Ending balance: {0}", endBalance);
9371

94-
My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
95-
}
9672
{% endhighlight %}
73+
{% include component-try-it.html href='https://dotnetfiddle.net/p67L8v' %}
9774

9875
### Result
9976
{% highlight text %}

docs/pages/linq/all.md

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,33 @@ This C# example uses the LINQ All method with a dynamic expression to determine
1818

1919
### LINQ
2020
{% highlight csharp %}
21-
private void uiAll_Simple_LINQ_Click(object sender, EventArgs e)
22-
{
23-
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
24-
25-
var onlyOdd = numbers.All(n => n % 2 == 1);
26-
27-
var sb = new StringBuilder();
21+
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
2822

29-
sb.AppendLine("The list contains only odd numbers: {0}", onlyOdd);
23+
var onlyOdd = numbers.All(n => n % 2 == 1);
3024

31-
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
32-
}
25+
Console.WriteLine("The list contains only odd numbers: {0}", onlyOdd);
3326
{% endhighlight %}
27+
{% include component-try-it.html href='https://dotnetfiddle.net/E82Y4a' %}
3428

3529
### LINQ Dynamic
3630
{% highlight csharp %}
37-
private void uiAll_Simple_LINQ_Dynamic_Click(object sender, EventArgs e)
38-
{
39-
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
31+
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
4032

41-
var onlyOdd = numbers.All(n => "n % 2 == 1");
33+
var onlyOdd = numbers.All(n => "n % 2 == 1");
4234

43-
var sb = new StringBuilder();
44-
45-
sb.AppendLine("The list contains only odd numbers: {0}", onlyOdd);
46-
47-
My.Result.Show(My.LinqResultType.LinqDynamic, uiResult, sb);
48-
}
35+
Console.WriteLine("The list contains only odd numbers: {0}", onlyOdd);
4936
{% endhighlight %}
37+
{% include component-try-it.html href='https://dotnetfiddle.net/1M0scW' %}
5038

5139
### LINQ Execute
5240
{% highlight csharp %}
53-
private void uiAll_Simple_LINQ_Execute_Click(object sender, EventArgs e)
54-
{
55-
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
41+
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
5642

57-
var onlyOdd = numbers.Execute<bool>("All(n => n % 2 == 1)");
43+
var onlyOdd = numbers.Execute<bool>("All(n => n % 2 == 1)");
5844

59-
var sb = new StringBuilder();
60-
61-
sb.AppendLine("The list contains only odd numbers: {0}", onlyOdd);
62-
63-
My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
64-
}
45+
Console.WriteLine("The list contains only odd numbers: {0}", onlyOdd);
6546
{% endhighlight %}
47+
{% include component-try-it.html href='https://dotnetfiddle.net/8kTOjI' %}
6648

6749
### Result
6850
{% highlight text %}
@@ -77,21 +59,24 @@ This C# example uses the LINQ All method with a dynamic expression to return a g
7759

7860
### LINQ
7961
{% highlight csharp %}
80-
private void uiAll_Grouped_LINQ_Click(object sender, EventArgs e)
81-
{
82-
var products = My.GetProductList();
62+
var products = getList();
8363

84-
var productGroups = products.GroupBy(p => p.Category)
85-
.Where(g => g.All(p => p.UnitsInStock > 0))
86-
.Select(g => new {Category = g.Key, Products = g});
64+
var productGroups = products.GroupBy(p => p.Category)
65+
.Where(g => g.All(p => p.UnitsInStock > 0))
66+
.Select(g => new {Category = g.Key, Products = g});
8767

88-
var sb = new StringBuilder();
68+
Console.WriteLine("Count before All : " + products.Count());
8969

90-
My.ObjectDumper.Write(sb, productGroups, 1);
70+
int newCount = 0;
9171

92-
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
72+
foreach (var group in productGroups)
73+
{
74+
newCount+= group.Products.Count();
9375
}
76+
77+
Console.WriteLine("Count After All : " + newCount);
9478
{% endhighlight %}
79+
{% include component-try-it.html href='https://dotnetfiddle.net/COqjUY' %}
9580

9681
### LINQ Dynamic
9782
{% highlight csharp %}

0 commit comments

Comments
 (0)