Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/CNAME
Original file line number Diff line number Diff line change
@@ -1 +1 @@
eval-expression.net
eval-expression.net
1 change: 1 addition & 0 deletions docs/_includes/component-try-it.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="{{ include.href }}">try it online</a>
8 changes: 7 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ int result = Eval.Execute<int>(@"
// - Anonymous Type
// - Extension Methods
// - Generic Type
{% endhighlight %}
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/MHoctF' %}
</div>
</div>
</div>
Expand Down Expand Up @@ -251,6 +252,7 @@ int result = Eval.Execute<int>(@"
var list = new List<int>() { 1, 2, 3, 4, 5 };
return list.Where(x => x > X).Take(Y).Count();", new { X = 1, Y = 2});
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/j3WHx1' %}
</div>
</div>
</div>
Expand Down Expand Up @@ -304,6 +306,8 @@ int result = Eval.Execute<int>("X + Y", values);
// Argument Position
int result = Eval.Execute<int>("{0} + {1}", 1, 2);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/V6cZ0K' %}

</div>
</div>

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

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

Expand Down
2 changes: 2 additions & 0 deletions docs/pages/api/compile-execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var context = new EvalContext();
string code = "Price * Quantity";
var price = context.Execute<decimal>(code, orderItem);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/tzBdMI' %}

## Compile
Compile a C# expression and return a delegate:
Expand Down Expand Up @@ -60,3 +61,4 @@ foreach(var item in list)
totals += compiled(item);
}
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/00YSGK' %}
2 changes: 2 additions & 0 deletions docs/pages/api/eval-compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ compiled(1, 2);
var compiled = Eval.Compile<Func<int, int, int>>("X + Y", "X", "Y");
int result = compiled(1, 2);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/MBHlX8' %}

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


2 changes: 2 additions & 0 deletions docs/pages/api/eval-execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ int result = Eval.Execute<int>("X + Y", expandoObject);
var values = new Dictionary<string, object>() { {"X", 1}, {"Y", 2} };
int result = Eval.Execute<int>("X + Y", values);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/W9TwcP' %}

## Execute and return an object result
You can return the result as an object:
Expand All @@ -72,3 +73,4 @@ object result = Eval.Execute("X + Y", expandoObject);
var values = new Dictionary<string, object>() { {"X", 1}, {"Y", 2} };
object result = Eval.Execute("X + Y", values);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/8mtLH8' %}
1 change: 1 addition & 0 deletions docs/pages/api/linq-dynamic.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var list = new List<int>() { 1, 2, 3, 4, 5 };
var list2 = list.Where(x => "x > 2");
var list3 = list.Where(x => "x > X", new { X = 2 }); // with parameter
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/S42mkU' %}

## LINQ Dynamic - Ordering and Selecting
You can use any ordering and selecting method with a dynamic C# expression:
Expand Down
2 changes: 2 additions & 0 deletions docs/pages/api/string-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Execute a C# expression. Extend the String class.
var result1 = "1+2".Execute<int>(); // return 3
var result2 = "X+Y".Execute(new { X = 1, Y = 2 }); // return 3
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/iXeE87' %}


## "string".Compile
Compile a C# expression. Extend the String class.
Expand Down
59 changes: 18 additions & 41 deletions docs/pages/linq/aggregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,22 @@ This C# example uses the LINQ Aggregate method with a dynamic expression to crea

### LINQ
{% highlight csharp %}
private void uiAggregate_Simple_LINQ_Click(object sender, EventArgs e)
{
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};

var product = doubles.Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor);
var product = doubles.Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor);

var sb = new StringBuilder();

sb.AppendLine("Total product of all numbers: {0}", product);

My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
}
Console.WriteLine("Total product of all numbers: {0}", product);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/BZLbt5' %}

### LINQ Execute
{% highlight csharp %}
private void uiAggregate_Simple_LINQ_Execute_Click(object sender, EventArgs e)
{
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};

var product = doubles.Execute<double>("Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor)");

var sb = new StringBuilder();
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};

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

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

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

### LINQ
{% highlight csharp %}
private void uiAggregate_Seed_LINQ_Click(object sender, EventArgs e)
{
var startBalance = 100.0;
var startBalance = 100.0;

int[] attemptedWithdrawals = {20, 10, 40, 50, 10, 70, 30};
int[] attemptedWithdrawals = {20, 10, 40, 50, 10, 70, 30};

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

var sb = new StringBuilder();

sb.AppendLine("Ending balance: {0}", endBalance);

My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
}
Console.WriteLine("Ending balance: {0}", endBalance);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/LqobT0' %}

### LINQ Execute
{% highlight csharp %}
private void uiAggregate_Seed_LINQ_Execute_Click(object sender, EventArgs e)
{
var startBalance = 100.0;

int[] attemptedWithdrawals = {20, 10, 40, 50, 10, 70, 30};
var startBalance = 100.0;

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

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

sb.AppendLine("Ending balance: {0}", endBalance);
Console.WriteLine("Ending balance: {0}", endBalance);

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

### Result
{% highlight text %}
Expand Down
63 changes: 24 additions & 39 deletions docs/pages/linq/all.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,33 @@ This C# example uses the LINQ All method with a dynamic expression to determine

### LINQ
{% highlight csharp %}
private void uiAll_Simple_LINQ_Click(object sender, EventArgs e)
{
int[] numbers = {1, 11, 3, 19, 41, 65, 19};

var onlyOdd = numbers.All(n => n % 2 == 1);

var sb = new StringBuilder();
int[] numbers = {1, 11, 3, 19, 41, 65, 19};

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

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

### LINQ Dynamic
{% highlight csharp %}
private void uiAll_Simple_LINQ_Dynamic_Click(object sender, EventArgs e)
{
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
int[] numbers = {1, 11, 3, 19, 41, 65, 19};

var onlyOdd = numbers.All(n => "n % 2 == 1");
var onlyOdd = numbers.All(n => "n % 2 == 1");

var sb = new StringBuilder();

sb.AppendLine("The list contains only odd numbers: {0}", onlyOdd);

My.Result.Show(My.LinqResultType.LinqDynamic, uiResult, sb);
}
Console.WriteLine("The list contains only odd numbers: {0}", onlyOdd);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/1M0scW' %}

### LINQ Execute
{% highlight csharp %}
private void uiAll_Simple_LINQ_Execute_Click(object sender, EventArgs e)
{
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
int[] numbers = {1, 11, 3, 19, 41, 65, 19};

var onlyOdd = numbers.Execute<bool>("All(n => n % 2 == 1)");
var onlyOdd = numbers.Execute<bool>("All(n => n % 2 == 1)");

var sb = new StringBuilder();

sb.AppendLine("The list contains only odd numbers: {0}", onlyOdd);

My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
}
Console.WriteLine("The list contains only odd numbers: {0}", onlyOdd);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/8kTOjI' %}

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

### LINQ
{% highlight csharp %}
private void uiAll_Grouped_LINQ_Click(object sender, EventArgs e)
{
var products = My.GetProductList();
var products = getList();

var productGroups = products.GroupBy(p => p.Category)
.Where(g => g.All(p => p.UnitsInStock > 0))
.Select(g => new {Category = g.Key, Products = g});
var productGroups = products.GroupBy(p => p.Category)
.Where(g => g.All(p => p.UnitsInStock > 0))
.Select(g => new {Category = g.Key, Products = g});

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

My.ObjectDumper.Write(sb, productGroups, 1);
int newCount = 0;

My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
foreach (var group in productGroups)
{
newCount+= group.Products.Count();
}

Console.WriteLine("Count After All : " + newCount);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/COqjUY' %}

### LINQ Dynamic
{% highlight csharp %}
Expand Down
64 changes: 24 additions & 40 deletions docs/pages/linq/any.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,33 @@ This C# example uses the LINQ Any method with a dynamic expression to determine

### LINQ
{% highlight csharp %}
private void uiAny_Simple_LINQ_Click(object sender, EventArgs e)
{
string[] words = {"believe", "relief", "receipt", "field"};

var iAfterE = words.Any(w => w.Contains("ei"));

var sb = new StringBuilder();
string[] words = {"believe", "relief", "receipt", "field"};

sb.AppendLine("There is a word that contains in the list that contains 'ei': {0}", iAfterE);
var iAfterE = words.Any(w => w.Contains("ei"));

My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
}
Console.WriteLine("There is a word that contains in the list that contains 'ei': {0}", iAfterE);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/36Tkzn' %}

### LINQ Dynamic
{% highlight csharp %}
private void uiAny_Simple_LINQ_Dynamic_Click(object sender, EventArgs e)
{
string[] words = {"believe", "relief", "receipt", "field"};
string[] words = {"believe", "relief", "receipt", "field"};

var iAfterE = words.Any(w => "w.Contains('ei')");
var iAfterE = words.Any(w => "w.Contains('ei')");

var sb = new StringBuilder();

sb.AppendLine("There is a word that contains in the list that contains 'ei': {0}", iAfterE);

My.Result.Show(My.LinqResultType.LinqDynamic, uiResult, sb);
}
Console.WriteLine("There is a word that contains in the list that contains 'ei': {0}", iAfterE);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/gXwUhP' %}

### LINQ Execute
{% highlight csharp %}
private void uiAny_Simple_LINQ_Execute_Click(object sender, EventArgs e)
{
string[] words = {"believe", "relief", "receipt", "field"};
string[] words = {"believe", "relief", "receipt", "field"};

var iAfterE = words.Execute<bool>("Any(w => w.Contains('ei'))");
var iAfterE = words.Execute<bool>("Any(w => w.Contains('ei'))");

var sb = new StringBuilder();

sb.AppendLine("There is a word that contains in the list that contains 'ei': {0}", iAfterE);

My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
}
Console.WriteLine("There is a word that contains in the list that contains 'ei': {0}", iAfterE);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/PEGWxp' %}

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

### LINQ
{% highlight csharp %}
var products = getList();

private void uiAny_Grouped_LINQ_Click(object sender, EventArgs e)
{
var products = My.GetProductList();

var productGroups = products.GroupBy(p => p.Category)
.Where(g => g.Any(p => p.UnitsInStock == 0))
.Select(g => new {Category = g.Key, Products = g});
var productGroups = products.GroupBy(p => p.Category)
.Where(g => g.Any(p => p.UnitsInStock == 0))
.Select(g => new {Category = g.Key, Products = g});

var sb = new StringBuilder();
Console.WriteLine("Count before Any : " + products.Count());

My.ObjectDumper.Write(sb, productGroups, 1);
int newCount = 0;

My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
foreach (var group in productGroups)
{
newCount+= group.Products.Count();
}

Console.WriteLine("Count After Any : " + newCount);
{% endhighlight %}
{% include component-try-it.html href='https://dotnetfiddle.net/GXuk1q' %}

### LINQ Dynamic
{% highlight csharp %}
Expand Down
Loading