diff --git a/docs/CNAME b/docs/CNAME index 228b903..7c97280 100644 --- a/docs/CNAME +++ b/docs/CNAME @@ -1 +1 @@ -eval-expression.net \ No newline at end of file +eval-expression.net diff --git a/docs/_includes/component-try-it.html b/docs/_includes/component-try-it.html new file mode 100644 index 0000000..5b01736 --- /dev/null +++ b/docs/_includes/component-try-it.html @@ -0,0 +1 @@ +try it online diff --git a/docs/index.md b/docs/index.md index 45c3beb..402e618 100644 --- a/docs/index.md +++ b/docs/index.md @@ -219,7 +219,8 @@ int result = Eval.Execute(@" // - Anonymous Type // - Extension Methods // - Generic Type -{% endhighlight %} +{% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/MHoctF' %} @@ -251,6 +252,7 @@ int result = Eval.Execute(@" var list = new List() { 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' %} @@ -304,6 +306,8 @@ int result = Eval.Execute("X + Y", values); // Argument Position int result = Eval.Execute("{0} + {1}", 1, 2); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/V6cZ0K' %} + @@ -326,6 +330,7 @@ int result = Eval.Execute(@" var list = new List() { 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' %} @@ -350,6 +355,7 @@ var customer = new Customer() { Name = "ZZZ" }; var nameGetter = Eval.Compile>("x.Name", "x"); var name = nameGetter(customer); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/yW8S35' %} diff --git a/docs/pages/api/compile-execute.md b/docs/pages/api/compile-execute.md index 08bf93f..f50b6fe 100644 --- a/docs/pages/api/compile-execute.md +++ b/docs/pages/api/compile-execute.md @@ -30,6 +30,7 @@ var context = new EvalContext(); string code = "Price * Quantity"; var price = context.Execute(code, orderItem); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/tzBdMI' %} ## Compile Compile a C# expression and return a delegate: @@ -60,3 +61,4 @@ foreach(var item in list) totals += compiled(item); } {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/00YSGK' %} diff --git a/docs/pages/api/eval-compile.md b/docs/pages/api/eval-compile.md index 500f158..21f749c 100644 --- a/docs/pages/api/eval-compile.md +++ b/docs/pages/api/eval-compile.md @@ -33,6 +33,7 @@ compiled(1, 2); var compiled = Eval.Compile>("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: @@ -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' %} diff --git a/docs/pages/api/eval-execute.md b/docs/pages/api/eval-execute.md index 9aa4217..18768cf 100644 --- a/docs/pages/api/eval-execute.md +++ b/docs/pages/api/eval-execute.md @@ -47,6 +47,7 @@ int result = Eval.Execute("X + Y", expandoObject); var values = new Dictionary() { {"X", 1}, {"Y", 2} }; int result = Eval.Execute("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: @@ -72,3 +73,4 @@ object result = Eval.Execute("X + Y", expandoObject); var values = new Dictionary() { {"X", 1}, {"Y", 2} }; object result = Eval.Execute("X + Y", values); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/8mtLH8' %} diff --git a/docs/pages/api/linq-dynamic.md b/docs/pages/api/linq-dynamic.md index 3f15424..9fa4ffb 100644 --- a/docs/pages/api/linq-dynamic.md +++ b/docs/pages/api/linq-dynamic.md @@ -40,6 +40,7 @@ var list = new List() { 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: diff --git a/docs/pages/api/string-extensions.md b/docs/pages/api/string-extensions.md index c9f83d4..8de80a5 100644 --- a/docs/pages/api/string-extensions.md +++ b/docs/pages/api/string-extensions.md @@ -35,6 +35,8 @@ Execute a C# expression. Extend the String class. var result1 = "1+2".Execute(); // 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. diff --git a/docs/pages/linq/aggregate.md b/docs/pages/linq/aggregate.md index 776984a..e539130 100644 --- a/docs/pages/linq/aggregate.md +++ b/docs/pages/linq/aggregate.md @@ -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("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("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 @@ -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("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("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 %} diff --git a/docs/pages/linq/all.md b/docs/pages/linq/all.md index 83b7780..eafa3be 100644 --- a/docs/pages/linq/all.md +++ b/docs/pages/linq/all.md @@ -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("All(n => n % 2 == 1)"); +var onlyOdd = numbers.Execute("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 %} @@ -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 %} diff --git a/docs/pages/linq/any.md b/docs/pages/linq/any.md index f99b8a3..c796df5 100644 --- a/docs/pages/linq/any.md +++ b/docs/pages/linq/any.md @@ -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("Any(w => w.Contains('ei'))"); +var iAfterE = words.Execute("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 %} @@ -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 %} diff --git a/docs/pages/linq/average.md b/docs/pages/linq/average.md index 5a1fce1..eb6c698 100644 --- a/docs/pages/linq/average.md +++ b/docs/pages/linq/average.md @@ -19,35 +19,24 @@ This C# example uses the LINQ Average method with a dynamic expression to get th ### LINQ {% highlight csharp %} -private void uiAverage_Simple_LINQ_Click(object sender, EventArgs e) -{ - int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - - var averageNum = numbers.Average(); - - var sb = new StringBuilder(); +int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - sb.AppendLine("The average number is {0}.", averageNum); +var averageNum = numbers.Average(); - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); -} +Console.WriteLine("The average number is {0}.", averageNum); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/ytINV0' %} + ### LINQ Execute {% highlight csharp %} -private void uiAverage_Simple_LINQ_Execute_Click(object sender, EventArgs e) -{ - int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - - var averageNum = numbers.Execute("Average()"); +int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - var sb = new StringBuilder(); - - sb.AppendLine("The average number is {0}.", averageNum); +var averageNum = numbers.Execute("Average()"); - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); -} +Console.WriteLine("The average number is {0}.", averageNum); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/0eEHRS' %} ### Result {% highlight text %} @@ -62,35 +51,23 @@ This C# example uses the LINQ Average method with a dynamic expression to get th ### LINQ {% highlight csharp %} -private void uiAverage_Projection_LINQ_Click(object sender, EventArgs e) -{ - string[] words = {"cherry", "apple", "blueberry"}; - - var averageLength = words.Average(w => w.Length); - - var sb = new StringBuilder(); +string[] words = {"cherry", "apple", "blueberry"}; - sb.AppendLine("The average word length is {0} characters.", averageLength); +var averageLength = words.Average(w => w.Length); - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); -} +Console.WriteLine("The average word length is {0} characters.", averageLength); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/CjVP6t' %} ### LINQ Execute {% highlight csharp %} -private void uiAverage_Projection_LINQ_Execute_Click(object sender, EventArgs e) -{ - string[] words = {"cherry", "apple", "blueberry"}; - - var averageLength = words.Execute("Average(w => w.Length)"); - - var sb = new StringBuilder(); +string[] words = {"cherry", "apple", "blueberry"}; - sb.AppendLine("The average word length is {0} characters.", averageLength); +var averageLength = words.Execute("Average(w => w.Length)"); - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); -} +Console.WriteLine("The average word length is {0} characters.", averageLength); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/xmIXWV' %} ### Result {% highlight text %} @@ -105,20 +82,16 @@ This C# example uses the LINQ Average method with a dynamic expression to get th ### LINQ {% highlight csharp %} -private void uiAverage_Grouped_LINQ_Click(object sender, EventArgs e) -{ - var products = My.GetProductList(); - - var categories = products.GroupBy(prod => prod.Category).Select(g => new {Category = g.Key, AveragePrice = g.Average(prod => prod.UnitPrice)}); +var products = getList(); - var sb = new StringBuilder(); +var categories = products.GroupBy(prod => prod.Category).Select(g => new {Category = g.Key, AveragePrice = g.Average(prod => prod.UnitPrice)}); - My.ObjectDumper.Write(sb, categories); - - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); +foreach (var categorie in categories) +{ + Console.WriteLine("Category : " + categorie.Category + " AveragePrice : " +categorie.AveragePrice ); } {% endhighlight %} - +{% include component-try-it.html href='https://dotnetfiddle.net/XtBI9y' %} ### LINQ Execute {% highlight csharp %} diff --git a/docs/pages/linq/combine.md b/docs/pages/linq/combine.md index 4a3feb6..aaf0ffd 100644 --- a/docs/pages/linq/combine.md +++ b/docs/pages/linq/combine.md @@ -17,39 +17,26 @@ This C# example uses the LINQ Combine method with a dynamic expression to calcul ### LINQ {% highlight csharp %} -private void uiCombine_LINQ_Click(object sender, EventArgs e) -{ - int[] vectorA = {0, 2, 4, 5, 6}; - int[] vectorB = {1, 3, 5, 7, 8}; +int[] vectorA = {0, 2, 4, 5, 6}; +int[] vectorB = {1, 3, 5, 7, 8}; - var dotProduct = vectorA.Combine(vectorB, (a, b) => a * b).Sum(); +var dotProduct = vectorA.Combine(vectorB, (a, b) => a * b).Sum(); - var sb = new StringBuilder(); - - sb.AppendLine("Dot product: {0}", dotProduct); - - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); -} +Console.WriteLine("Dot product: {0}", dotProduct); {% endhighlight %} - +{% include component-try-it.html href='https://dotnetfiddle.net/sqa5uV' %} ### LINQ Execute {% highlight csharp %} -private void uiCombine_LINQ_Execute_Click(object sender, EventArgs e) -{ - int[] vectorA = {0, 2, 4, 5, 6}; - int[] vectorB = {1, 3, 5, 7, 8}; - - EvalManager.DefaultContext.RegisterExtensionMethod(typeof(CustomSequenceOperators)); - var dotProduct = vectorA.Execute("Combine(vectorB, (a, b) => a * b).Sum()", new {vectorB}); - - var sb = new StringBuilder(); +int[] vectorA = {0, 2, 4, 5, 6}; +int[] vectorB = {1, 3, 5, 7, 8}; - sb.AppendLine("Dot product: {0}", dotProduct); +EvalManager.DefaultContext.RegisterExtensionMethod(typeof(CustomSequenceOperators)); +var dotProduct = vectorA.Execute("Combine(vectorB, (a, b) => a * b).Sum()", new {vectorB}); - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); -} +Console.WriteLine("Dot product: {0}", dotProduct); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/DR5a6p' %} ### Result {% highlight text %} diff --git a/docs/pages/linq/concat.md b/docs/pages/linq/concat.md index 5861912..81c926a 100644 --- a/docs/pages/linq/concat.md +++ b/docs/pages/linq/concat.md @@ -19,44 +19,34 @@ This C# example uses the LINQ Concat method with a dynamic expression to create ### LINQ {% highlight csharp %} private void uiConcat_1_LINQ_Click(object sender, EventArgs e) -{ - int[] numbersA = {0, 2, 4, 5, 6, 8, 9}; - int[] numbersB = {1, 3, 5, 7, 8}; - - var allNumbers = numbersA.Concat(numbersB); - - var sb = new StringBuilder(); +int[] numbersA = {0, 2, 4, 5, 6, 8, 9}; +int[] numbersB = {1, 3, 5, 7, 8}; - sb.AppendLine("All numbers from both arrays:"); - foreach (var n in allNumbers) - { - sb.AppendLine(n.ToString()); - } +var allNumbers = numbersA.Concat(numbersB); - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); +Console.WriteLine("All numbers from both arrays:"); +foreach (var n in allNumbers) +{ + Console.WriteLine(n); } {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/bwa68e' %} ### LINQ Execute {% highlight csharp %} -private void uiConcat_1_LINQ_Execute_Click(object sender, EventArgs e) -{ - int[] numbersA = {0, 2, 4, 5, 6, 8, 9}; - int[] numbersB = {1, 3, 5, 7, 8}; +int[] numbersA = {0, 2, 4, 5, 6, 8, 9}; +int[] numbersB = {1, 3, 5, 7, 8}; - var allNumbers = numbersA.Execute>("Concat(numbersB)", new {numbersB}); +var allNumbers = numbersA.Execute>("Concat(numbersB)", new {numbersB}); - var sb = new StringBuilder(); - sb.AppendLine("All numbers from both arrays:"); - foreach (var n in allNumbers) - { - sb.AppendLine(n.ToString()); - } - - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); +Console.WriteLine("All numbers from both arrays:"); +foreach (var n in allNumbers) +{ + Console.WriteLine(n.ToString()); } {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/kIv2qY' %} ### Result {% highlight text %} diff --git a/docs/pages/linq/count.md b/docs/pages/linq/count.md index 1b461de..5ce9d5a 100644 --- a/docs/pages/linq/count.md +++ b/docs/pages/linq/count.md @@ -20,35 +20,23 @@ This C# example uses the LINQ Count method with a dynamic expression to get the ### LINQ {% highlight csharp %} -private void uiCount_Simple_LINQ_Click(object sender, EventArgs e) -{ - int[] factorsOf300 = {2, 2, 3, 5, 5}; - - var uniqueFactors = factorsOf300.Distinct().Count(); - - var sb = new StringBuilder(); +int[] factorsOf300 = {2, 2, 3, 5, 5}; - sb.AppendLine("There are {0} unique factors of 300.", uniqueFactors); +var uniqueFactors = factorsOf300.Distinct().Count(); - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); -} +Console.WriteLine("There are {0} unique factors of 300.", uniqueFactors); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/2HAQox' %} ### LINQ Execute {% highlight csharp %} -private void uiCount_Simple_LINQ_Execute_Click(object sender, EventArgs e) -{ - int[] factorsOf300 = {2, 2, 3, 5, 5}; +int[] factorsOf300 = {2, 2, 3, 5, 5}; - var uniqueFactors = factorsOf300.Distinct().Execute("Count()"); +var uniqueFactors = factorsOf300.Distinct().Execute("Count()"); - var sb = new StringBuilder(); - - sb.AppendLine("There are {0} unique factors of 300.", uniqueFactors); - - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); -} +Console.WriteLine("There are {0} unique factors of 300.", uniqueFactors); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/1Xc6yM' %} ### Result {% highlight text %} @@ -63,51 +51,33 @@ This C# example uses the LINQ Count method with a dynamic expression to get the ### LINQ {% highlight csharp %} -private void uiCount_Conditional_LINQ_Click(object sender, EventArgs e) -{ - int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - - var oddNumbers = numbers.Count(n => n % 2 == 1); +int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - var sb = new StringBuilder(); +var oddNumbers = numbers.Count(n => n % 2 == 1); - sb.AppendLine("There are {0} odd numbers in the list.", oddNumbers); - - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); -} +Console.WriteLine("There are {0} odd numbers in the list.", oddNumbers); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/3LGjG3' %} ### LINQ Dynamic {% highlight csharp %} -private void uiCount_Conditional_LINQ_Dynamic_Click(object sender, EventArgs e) -{ - int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - - var oddNumbers = numbers.Count(n => "n % 2 == 1"); - - var sb = new StringBuilder(); +int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - sb.AppendLine("There are {0} odd numbers in the list.", oddNumbers); +var oddNumbers = numbers.Count(n => "n % 2 == 1"); - My.Result.Show(My.LinqResultType.LinqDynamic, uiResult, sb); -} +Console.WriteLine("There are {0} odd numbers in the list.", oddNumbers); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/P2zgkd' %} ### LINQ Execute {% highlight csharp %} -private void uiCount_Conditional_LINQ_Execute_Click(object sender, EventArgs e) -{ - int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; +int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - var oddNumbers = numbers.Execute("Count(n => n % 2 == 1)"); - - var sb = new StringBuilder(); +var oddNumbers = numbers.Execute("Count(n => n % 2 == 1)"); - sb.AppendLine("There are {0} odd numbers in the list.", oddNumbers); - - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); -} +Console.WriteLine("There are {0} odd numbers in the list.", oddNumbers); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/UY9frV' %} ### Result {% highlight text %} diff --git a/docs/pages/linq/distinct.md b/docs/pages/linq/distinct.md index 3e8fb7e..feeec26 100644 --- a/docs/pages/linq/distinct.md +++ b/docs/pages/linq/distinct.md @@ -18,43 +18,32 @@ This C# example uses the LINQ Distinct method with a dynamic expression to remov ### LINQ {% highlight csharp %} -private void uiDistinct_1_LINQ_Click(object sender, EventArgs e) -{ - int[] factorsOf300 = {2, 2, 3, 5, 5}; - - var uniqueFactors = factorsOf300.Distinct(); +int[] factorsOf300 = {2, 2, 3, 5, 5}; - var sb = new StringBuilder(); +var uniqueFactors = factorsOf300.Distinct(); - sb.AppendLine("Prime factors of 300:"); - foreach (var f in uniqueFactors) - { - sb.AppendLine(f.ToString()); - } - - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); +Console.WriteLine("Prime factors of 300:"); +foreach (var f in uniqueFactors) +{ + Console.WriteLine(f.ToString()); } {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/p6rdJI' %} ### LINQ Execute {% highlight csharp %} -private void uiDistinct_1_LINQ_Execute_Click(object sender, EventArgs e) -{ - int[] factorsOf300 = {2, 2, 3, 5, 5}; - - var uniqueFactors = factorsOf300.Execute>("Distinct()"); +int[] factorsOf300 = {2, 2, 3, 5, 5}; - var sb = new StringBuilder(); +var uniqueFactors = factorsOf300.Execute>("Distinct()"); - sb.AppendLine("Prime factors of 300:"); - foreach (var f in uniqueFactors) - { - sb.AppendLine(f.ToString()); - } - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); +Console.WriteLine("Prime factors of 300:"); +foreach (var f in uniqueFactors) +{ + Console.WriteLine(f.ToString()); } {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/uMxKIt' %} ### Result {% highlight text %} @@ -72,44 +61,31 @@ This C# example uses the LINQ Distinct method with a dynamic expression to find ### LINQ {% highlight csharp %} -private void uiDistinct_2_LINQ_Click(object sender, EventArgs e) -{ - var products = My.GetProductList(); +var products = getList(); - var categoryNames = products.Select(x => x.Category).Distinct(); +var categoryNames = products.Select(x => x.Category).Distinct(); - var sb = new StringBuilder(); - - sb.AppendLine("Category names:"); - foreach (var n in categoryNames) - { - sb.AppendLine(n); - } - - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); +Console.WriteLine("Category names:"); +foreach (var n in categoryNames) +{ + Console.WriteLine(n); } {% endhighlight %} - +{% include component-try-it.html href='https://dotnetfiddle.net/TZUcdy' %} ### LINQ Execute {% highlight csharp %} -private void uiDistinct_2_LINQ_Execute_Click(object sender, EventArgs e) -{ - var products = My.GetProductList(); - - var categoryNames = products.Execute>("Select(x => x.Category).Distinct()"); +var products = getList(); - var sb = new StringBuilder(); +var categoryNames = products.Execute>("Select(x => x.Category).Distinct()"); - sb.AppendLine("Category names:"); - foreach (var n in categoryNames) - { - sb.AppendLine(n); - } - - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); +Console.WriteLine("Category names:"); +foreach (var n in categoryNames) +{ + Console.WriteLine(n); } {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/gC6H2M' %} ### Result {% highlight text %} diff --git a/docs/pages/linq/elementat.md b/docs/pages/linq/elementat.md index 31d5c3e..7ed2d74 100644 --- a/docs/pages/linq/elementat.md +++ b/docs/pages/linq/elementat.md @@ -21,35 +21,23 @@ This C# example uses the LINQ ElementAt method with a dynamic expression to retr ### LINQ {% highlight csharp %} -private void uiElementAt_LINQ_Click(object sender, EventArgs e) -{ - int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; +int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - var fourthLowNum = numbers.Where(n => n > 5).ElementAt(1); // second number is index 1 because sequences use 0-based indexing +var fourthLowNum = numbers.Where(n => n > 5).ElementAt(1); // second number is index 1 because sequences use 0-based indexing - var sb = new StringBuilder(); - - sb.AppendLine("Second number > 5: {0}", fourthLowNum); - - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); -} +Console.WriteLine("Second number > 5: {0}", fourthLowNum); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/ML8HVw' %} ### LINQ Execute {% highlight csharp %} -private void uiElementAt_LINQ_Execute_Click(object sender, EventArgs e) -{ - int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - - var fourthLowNum = numbers.Where(n => n > 5).Execute("ElementAt(1)"); // second number is index 1 because sequences use 0-based indexing - - var sb = new StringBuilder(); +int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; - sb.AppendLine("Second number > 5: {0}", fourthLowNum); +var fourthLowNum = numbers.Where(n => n > 5).Execute("ElementAt(1)"); // second number is index 1 because sequences use 0-based indexing - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); -} +Console.WriteLine("Second number > 5: {0}", fourthLowNum); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/C77VYn' %} ### Result {% highlight text %} diff --git a/docs/pages/linq/equalall.md b/docs/pages/linq/equalall.md index 3e5399b..7cc796b 100644 --- a/docs/pages/linq/equalall.md +++ b/docs/pages/linq/equalall.md @@ -18,37 +18,26 @@ This C# example uses the LINQ EqualAll method with a dynamic expression to see i ### LINQ {% highlight csharp %} -private void uiEqualAll_1_LINQ_Click(object sender, EventArgs e) -{ - var wordsA = new[] {"cherry", "apple", "blueberry"}; - var wordsB = new[] {"cherry", "apple", "blueberry"}; +var wordsA = new[] {"cherry", "apple", "blueberry"}; +var wordsB = new[] {"cherry", "apple", "blueberry"}; - var match = wordsA.SequenceEqual(wordsB); +var match = wordsA.SequenceEqual(wordsB); - var sb = new StringBuilder(); - - sb.AppendLine("The sequences match: {0}", match); - - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); -} +Console.WriteLine("The sequences match: {0}", match); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/J7H8eE' %} ### LINQ Execute {% highlight csharp %} private void uiEqualAll_1_LINQ_Execute_Click(object sender, EventArgs e) -{ - var wordsA = new[] {"cherry", "apple", "blueberry"}; - var wordsB = new[] {"cherry", "apple", "blueberry"}; - - var match = wordsA.Execute("SequenceEqual(wordsB)", new {wordsB}); - - var sb = new StringBuilder(); +var wordsA = new[] {"cherry", "apple", "blueberry"}; +var wordsB = new[] {"cherry", "apple", "blueberry"}; - sb.AppendLine("The sequences match: {0}", match); +var match = wordsA.Execute("SequenceEqual(wordsB)", new {wordsB}); - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); -} +Console.WriteLine("The sequences match: {0}", match); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/Ahstcy' %} ### Result {% highlight text %} @@ -63,37 +52,25 @@ This C# example uses the LINQ EqualAll method with a dynamic expression to see i ### LINQ {% highlight csharp %} -private void uiEqualAll_2_LINQ_Click(object sender, EventArgs e) -{ - var wordsA = new[] {"cherry", "apple", "blueberry"}; - var wordsB = new[] {"apple", "blueberry", "cherry"}; +var wordsA = new[] {"cherry", "apple", "blueberry"}; +var wordsB = new[] {"apple", "blueberry", "cherry"}; - var match = wordsA.SequenceEqual(wordsB); +var match = wordsA.SequenceEqual(wordsB); - var sb = new StringBuilder(); - - sb.AppendLine("The sequences match: {0}", match); - - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); -} +Console.WriteLine("The sequences match: {0}", match); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/k3qskP' %} ### LINQ Execute {% highlight csharp %} -private void uiEqualAll_2_LINQ_Execute_Click(object sender, EventArgs e) -{ - var wordsA = new[] {"cherry", "apple", "blueberry"}; - var wordsB = new[] {"apple", "blueberry", "cherry"}; - - var match = wordsA.Execute("SequenceEqual(wordsB)", new {wordsB}); - - var sb = new StringBuilder(); +var wordsA = new[] {"cherry", "apple", "blueberry"}; +var wordsB = new[] {"apple", "blueberry", "cherry"}; - sb.AppendLine("The sequences match: {0}", match); +var match = wordsA.Execute("SequenceEqual(wordsB)", new {wordsB}); - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); -} +Console.WriteLine("The sequences match: {0}", match); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/WK4OED' %} ### Result {% highlight text %} diff --git a/docs/pages/linq/except.md b/docs/pages/linq/except.md index c4e261c..1deb764 100644 --- a/docs/pages/linq/except.md +++ b/docs/pages/linq/except.md @@ -18,45 +18,33 @@ This C# example uses the LINQ Except method with a dynamic expression to create ### LINQ {% highlight csharp %} -private void uiExcept_1_LINQ_Click(object sender, EventArgs e) -{ - int[] numbersA = {0, 2, 4, 5, 6, 8, 9}; - int[] numbersB = {1, 3, 5, 7, 8}; - - var aOnlyNumbers = numbersA.Except(numbersB); - - var sb = new StringBuilder(); +int[] numbersA = {0, 2, 4, 5, 6, 8, 9}; +int[] numbersB = {1, 3, 5, 7, 8}; - sb.AppendLine("Numbers in first array but not second array:"); - foreach (var n in aOnlyNumbers) - { - sb.AppendLine(n.ToString()); - } +var aOnlyNumbers = numbersA.Except(numbersB); - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); +Console.WriteLine("Numbers in first array but not second array:"); +foreach (var n in aOnlyNumbers) +{ + Console.WriteLine(n.ToString()); } {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/oynmkt' %} ### LINQ Execute {% highlight csharp %} -private void uiExcept_1_LINQ_Execute_Click(object sender, EventArgs e) -{ - int[] numbersA = {0, 2, 4, 5, 6, 8, 9}; - int[] numbersB = {1, 3, 5, 7, 8}; - - var aOnlyNumbers = numbersA.Execute>("Except(numbersB)", new {numbersB}); - - var sb = new StringBuilder(); +int[] numbersA = {0, 2, 4, 5, 6, 8, 9}; +int[] numbersB = {1, 3, 5, 7, 8}; - sb.AppendLine("Numbers in first array but not second array:"); - foreach (var n in aOnlyNumbers) - { - sb.AppendLine(n.ToString()); - } +var aOnlyNumbers = numbersA.Execute>("Except(numbersB)", new {numbersB}); - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); +Console.WriteLine("Numbers in first array but not second array:"); +foreach (var n in aOnlyNumbers) +{ + Console.WriteLine(n.ToString()); } {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/uPQUlu' %} ### Result {% highlight text %} diff --git a/docs/pages/linq/first.md b/docs/pages/linq/first.md index 73a8a4f..6af61fb 100644 --- a/docs/pages/linq/first.md +++ b/docs/pages/linq/first.md @@ -18,35 +18,23 @@ This C# example uses the LINQ First method with a dynamic expression to find the ### LINQ {% highlight csharp %} -private void uiFirst_Simple_LINQ_Click(object sender, EventArgs e) -{ - var products = My.GetProductList(); +var products =getList(); - var product12 = products.Where(p => p.ProductID == 12).First(); +var product = products.Where(p => p.ProductID == 12).First(); - var sb = new StringBuilder(); - - My.ObjectDumper.Write(sb, product12); - - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); -} +Console.WriteLine("ProductID : " + product.ProductID+ " ,ProductName : " + product.ProductName+ " ,Category : "+ product.Category+ " ,UnitPrice : "+ product.UnitPrice+" ,UnitsInStock : "+ product.UnitsInStock); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/klY7P0' %} ### LINQ Execute {% highlight csharp %} -private void uiFirst_Simple_LINQ_Execute_Click(object sender, EventArgs e) -{ - var products = My.GetProductList(); - - var product12 = products.Where(p => p.ProductID == 12).Execute("First()"); +var products =getList(); - var sb = new StringBuilder(); +var product = products.Where(p => p.ProductID == 12).Execute("First()"); - My.ObjectDumper.Write(sb, product12); - - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); -} +Console.WriteLine("ProductID : " + product.ProductID+ " ,ProductName : " + product.ProductName+ " ,Category : "+ product.Category+ " ,UnitPrice : "+ product.UnitPrice+" ,UnitsInStock : "+ product.UnitsInStock); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/BOAG8x' %} ### Result {% highlight text %} @@ -62,50 +50,33 @@ This C# example uses the LINQ First method with a dynamic expression to find the ### LINQ {% highlight csharp %} private void uiFirst_Condition_LINQ_Click(object sender, EventArgs e) -{ - string[] strings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; - - var startsWithO = strings.First(s => s[0] == 'o'); +string[] strings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; - var sb = new StringBuilder(); +var startsWithO = strings.First(s => s[0] == 'o'); - sb.AppendLine("A string starting with 'o': {0}", startsWithO); - - My.Result.Show(My.LinqResultType.Linq, uiResult, sb); -} +Console.WriteLine("A string starting with 'o': {0}", startsWithO); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/GjrQL8' %} ### LINQ Dynamic {% highlight csharp %} -private void uiFirst_Condition_LINQ_Dynamic_Click(object sender, EventArgs e) -{ - string[] strings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; - - var startsWithO = strings.First(s => "s[0] == 'o'"); - - var sb = new StringBuilder(); +string[] strings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; - sb.AppendLine("A string starting with 'o': {0}", startsWithO); +var startsWithO = strings.First(s => "s[0] == 'o'"); - My.Result.Show(My.LinqResultType.LinqDynamic, uiResult, sb); -} +Console.WriteLine("A string starting with 'o': {0}", startsWithO); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/B3H2GQ' %} ### LINQ Execute {% highlight csharp %} -private void uiFirst_Condition_LINQ_Execute_Click(object sender, EventArgs e) -{ - string[] strings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; - - var startsWithO = strings.Execute("First(s => s[0] == 'o')"); - - var sb = new StringBuilder(); +string[] strings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; - sb.AppendLine("A string starting with 'o': {0}", startsWithO); +var startsWithO = strings.Execute("First(s => s[0] == 'o')"); - My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb); -} +Console.WriteLine("A string starting with 'o': {0}", startsWithO); {% endhighlight %} +{% include component-try-it.html href='https://dotnetfiddle.net/pqhtyM' %} ### Result {% highlight text %}