From 8b86c38ce26294c2dee77ced63a0074d4368516e Mon Sep 17 00:00:00 2001 From: mgernand Date: Fri, 18 Jul 2014 16:35:34 +0200 Subject: [PATCH 1/7] Updated portable lib settings. Set version 1.0.3. Created some more extensions. --- .../ExpressionReflect.Tests.csproj | 5 ++-- Source/ExpressionReflect/ActionExtensions.cs | 24 +++++++++++++++++ .../ExpressionReflect.csproj | 2 +- Source/ExpressionReflect/FuncExtensions.cs | 24 +++++++++++++++++ Source/ExpressionReflect/TypeExtensions.cs | 26 ++++++++++++------- Source/Version.txt | 2 +- 6 files changed, 70 insertions(+), 13 deletions(-) diff --git a/Source/ExpressionReflect.Tests/ExpressionReflect.Tests.csproj b/Source/ExpressionReflect.Tests/ExpressionReflect.Tests.csproj index cc68cb3..c181d45 100644 --- a/Source/ExpressionReflect.Tests/ExpressionReflect.Tests.csproj +++ b/Source/ExpressionReflect.Tests/ExpressionReflect.Tests.csproj @@ -1,5 +1,5 @@  - + Debug @@ -9,10 +9,11 @@ Properties ExpressionReflect.Tests ExpressionReflect.Tests - v4.5 + v4.5.1 512 ..\ true + true diff --git a/Source/ExpressionReflect/ActionExtensions.cs b/Source/ExpressionReflect/ActionExtensions.cs index e95d113..b2d1ed7 100644 --- a/Source/ExpressionReflect/ActionExtensions.cs +++ b/Source/ExpressionReflect/ActionExtensions.cs @@ -34,5 +34,29 @@ public static Action Reflect(this Expression action = (a, b, c, d) => target.Execute(a, b, c, d); return action; } + + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e) => target.Execute(a, b, c, d, e); + return action; + } + + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e, f) => target.Execute(a, b, c, d, e, f); + return action; + } + + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e, f, g) => target.Execute(a, b, c, d, e, f, g); + return action; + } + + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e, f, g, h) => target.Execute(a, b, c, d, e, f, g, h); + return action; + } } } \ No newline at end of file diff --git a/Source/ExpressionReflect/ExpressionReflect.csproj b/Source/ExpressionReflect/ExpressionReflect.csproj index 0f6a0f5..ae13634 100644 --- a/Source/ExpressionReflect/ExpressionReflect.csproj +++ b/Source/ExpressionReflect/ExpressionReflect.csproj @@ -11,7 +11,7 @@ ExpressionReflect ExpressionReflect v4.0 - Profile154 + Profile344 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} diff --git a/Source/ExpressionReflect/FuncExtensions.cs b/Source/ExpressionReflect/FuncExtensions.cs index 8ee1427..ae5a1fe 100644 --- a/Source/ExpressionReflect/FuncExtensions.cs +++ b/Source/ExpressionReflect/FuncExtensions.cs @@ -34,5 +34,29 @@ public static Func Reflect(thi Func func = (a, b, c, d) => (TResult)target.Execute(a, b, c, d); return func; } + + public static Func Reflect(this Expression> target) + { + Func func = (a, b, c, d, e) => (TResult)target.Execute(a, b, c, d, e); + return func; + } + + public static Func Reflect(this Expression> target) + { + Func func = (a, b, c, d, e, f) => (TResult)target.Execute(a, b, c, d, e, f); + return func; + } + + public static Func Reflect(this Expression> target) + { + Func func = (a, b, c, d, e, f, g) => (TResult)target.Execute(a, b, c, d, e, f, g); + return func; + } + + public static Func Reflect(this Expression> target) + { + Func func = (a, b, c, d, e, f, g, h) => (TResult)target.Execute(a, b, c, d, e, f, g, h); + return func; + } } } \ No newline at end of file diff --git a/Source/ExpressionReflect/TypeExtensions.cs b/Source/ExpressionReflect/TypeExtensions.cs index 76b10bb..a650829 100644 --- a/Source/ExpressionReflect/TypeExtensions.cs +++ b/Source/ExpressionReflect/TypeExtensions.cs @@ -11,11 +11,15 @@ internal static bool IsFunc(this Type type) if(type.IsGenericType) { Type definition = type.GetGenericTypeDefinition(); - isFunc = definition == typeof(Func<>) || - definition == typeof(Func<,>) || - definition == typeof(Func<,,>) || - definition == typeof(Func<,,,>) || - definition == typeof(Func<,,,,>); + isFunc = definition == typeof (Func<>) || + definition == typeof (Func<,>) || + definition == typeof (Func<,,>) || + definition == typeof (Func<,,,>) || + definition == typeof (Func<,,,,>) || + definition == typeof (Func<,,,,,>) || + definition == typeof (Func<,,,,,,>) || + definition == typeof (Func<,,,,,,,>) || + definition == typeof (Func<,,,,,,,,>); } return isFunc; @@ -30,10 +34,14 @@ internal static bool IsAction(this Type type) Type definition = type.GetGenericTypeDefinition(); isAction = isAction || - definition == typeof(Action<>) || - definition == typeof(Action<,>) || - definition == typeof(Action<,,>) || - definition == typeof(Action<,,,>); + definition == typeof (Action<>) || + definition == typeof (Action<,>) || + definition == typeof (Action<,,>) || + definition == typeof (Action<,,,>) || + definition == typeof (Action<,,,,>) || + definition == typeof (Action<,,,,,>) || + definition == typeof (Action<,,,,,,>) || + definition == typeof (Action<,,,,,,,>); } return isAction; diff --git a/Source/Version.txt b/Source/Version.txt index 67539e4..12cf88d 100644 --- a/Source/Version.txt +++ b/Source/Version.txt @@ -1 +1 @@ -1.0.2.0 \ No newline at end of file +1.0.3.0 \ No newline at end of file From 14ab1a385e0f2c30ee1c7962b5f399ae44dd7f00 Mon Sep 17 00:00:00 2001 From: mgernand Date: Sun, 20 Jul 2014 00:44:06 +0200 Subject: [PATCH 2/7] Updated link to source of the Evaluator class. The old link was dead. --- Source/ExpressionReflect/Evaluator.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/ExpressionReflect/Evaluator.cs b/Source/ExpressionReflect/Evaluator.cs index 9cd7886..70588e4 100644 --- a/Source/ExpressionReflect/Evaluator.cs +++ b/Source/ExpressionReflect/Evaluator.cs @@ -8,12 +8,12 @@ /// Enables the partial evaluation of queries. /// /// - /// From http://msdn.microsoft.com/en-us/library/bb546158.aspx + /// From http://blogs.msdn.com/b/mattwar/archive/2007/08/01/linq-building-an-iqueryable-provider-part-iii.aspx /// public static class Evaluator { /// - /// Performs evaluation & replacement of independent sub-trees + /// Performs evaluation & replacement of independent sub-trees. /// /// The root of the expression tree. /// A new tree with sub-trees evaluated and replaced. @@ -23,7 +23,7 @@ public static Expression PartialEval(this Expression expression) } /// - /// Performs evaluation & replacement of independent sub-trees + /// Performs evaluation & replacement of independent sub-trees. /// /// The root of the expression tree. /// A function that decides whether a given expression node can be part of the local function. @@ -39,7 +39,7 @@ private static bool CanBeEvaluatedLocally(Expression expression) } /// - /// Evaluates & replaces sub-trees when first candidate is reached (top-down) + /// Evaluates & replaces sub-trees when first candidate is reached (top-down). /// private class SubtreeEvaluator : ExpressionVisitor { From 0101be2f61dd0148ba2b91e6b6216fce17d3214f Mon Sep 17 00:00:00 2001 From: mgernand Date: Wed, 23 Jul 2014 21:43:23 +0200 Subject: [PATCH 3/7] Modified README.md --- README.md | 5 ++++- Source/ExpressionReflect/ExpressionReflect.csproj | 7 +------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9b9410c..882f061 100644 --- a/README.md +++ b/README.md @@ -197,4 +197,7 @@ All this features can be combined to more complex expressions. Contributors ------------ -Bernhard Richter (seesharper) \ No newline at end of file +Bernhard Richter (seesharper) + + +Thank you! \ No newline at end of file diff --git a/Source/ExpressionReflect/ExpressionReflect.csproj b/Source/ExpressionReflect/ExpressionReflect.csproj index ae13634..96f6df9 100644 --- a/Source/ExpressionReflect/ExpressionReflect.csproj +++ b/Source/ExpressionReflect/ExpressionReflect.csproj @@ -39,7 +39,7 @@ bin\Release\ExpressionReflect.xml - true + false ..\..\ExpressionReflect.snk @@ -58,11 +58,6 @@ - - - ExpressionReflect.snk - - - - - + + + From f70aba0bf661dd81bed3509b5945ea068a28808b Mon Sep 17 00:00:00 2001 From: mgernand Date: Mon, 28 Jul 2014 21:15:21 +0200 Subject: [PATCH 5/7] Added more extension methods. Added LocalCollectionExpander class. --- .../BinaryOperatorTests.cs | 74 +-- .../ExpressionReflect.Tests/EvaluatorTests.cs | 82 ++- .../FuncExecutionTests.cs | 70 +- Source/ExpressionReflect/ActionExtensions.cs | 66 ++ Source/ExpressionReflect/Evaluator.cs | 9 +- .../ExpressionReflect/ExpressionExtensions.cs | 8 + .../ExpressionReflect.csproj | 6 +- .../ExpressionReflectionExecutor.cs | 182 +++-- Source/ExpressionReflect/FuncExtensions.cs | 66 ++ .../JetBrains.Annotations.cs | 624 ++++++++++++++++++ .../LocalCollectionExpander .cs | 90 +++ .../ExpressionReflect/PredicateExtensions.cs | 2 + Source/ExpressionReflect/TypeExtensions.cs | 19 +- Source/ExpressionReflect/Utility.cs | 33 + Source/Version.txt | 2 +- 15 files changed, 1165 insertions(+), 168 deletions(-) create mode 100644 Source/ExpressionReflect/JetBrains.Annotations.cs create mode 100644 Source/ExpressionReflect/LocalCollectionExpander .cs create mode 100644 Source/ExpressionReflect/Utility.cs diff --git a/Source/ExpressionReflect.Tests/BinaryOperatorTests.cs b/Source/ExpressionReflect.Tests/BinaryOperatorTests.cs index 0a62f65..c97db39 100644 --- a/Source/ExpressionReflect.Tests/BinaryOperatorTests.cs +++ b/Source/ExpressionReflect.Tests/BinaryOperatorTests.cs @@ -76,43 +76,43 @@ public void ShouldExecuteOperator_TypeIs() reflectionResult.Should().Be(emitResult); } - [Test] - public void ShouldExecuteOperator_Equals() - { - // Arrange - Expression> expression = s => s == "SomeValue"; - - // Act - Func emit = expression.Compile(); - Func reflection = expression.Reflect(); - - bool emitResult = emit.Invoke("SomeValue"); - bool reflectionResult = reflection.Invoke("SomeValue"); - - // Assert - emitResult.Should().BeTrue(); - reflectionResult.Should().BeTrue(); - reflectionResult.Should().Be(emitResult); - } - - [Test] - public void ShouldExecuteOperator_EqualsWithNullValue() - { - // Arrange - Expression> expression = s => s == null; - - // Act - Func emit = expression.Compile(); - Func reflection = expression.Reflect(); - - bool emitResult = emit.Invoke(null); - bool reflectionResult = reflection.Invoke(null); - - // Assert - emitResult.Should().BeTrue(); - reflectionResult.Should().BeTrue(); - reflectionResult.Should().Be(emitResult); - } + [Test] + public void ShouldExecuteOperator_Equals() + { + // Arrange + Expression> expression = s => s == "SomeValue"; + + // Act + Func emit = expression.Compile(); + Func reflection = expression.Reflect(); + + bool emitResult = emit.Invoke("SomeValue"); + bool reflectionResult = reflection.Invoke("SomeValue"); + + // Assert + emitResult.Should().BeTrue(); + reflectionResult.Should().BeTrue(); + reflectionResult.Should().Be(emitResult); + } + + [Test] + public void ShouldExecuteOperator_EqualsWithNullValue() + { + // Arrange + Expression> expression = s => s == null; + + // Act + Func emit = expression.Compile(); + Func reflection = expression.Reflect(); + + bool emitResult = emit.Invoke(null); + bool reflectionResult = reflection.Invoke(null); + + // Assert + emitResult.Should().BeTrue(); + reflectionResult.Should().BeTrue(); + reflectionResult.Should().Be(emitResult); + } } } diff --git a/Source/ExpressionReflect.Tests/EvaluatorTests.cs b/Source/ExpressionReflect.Tests/EvaluatorTests.cs index ddd2e19..afb2f3a 100644 --- a/Source/ExpressionReflect.Tests/EvaluatorTests.cs +++ b/Source/ExpressionReflect.Tests/EvaluatorTests.cs @@ -2,6 +2,9 @@ namespace ExpressionReflect.Tests { using System; + using System.Collections; + using System.Collections.Generic; + using System.Linq; using System.Linq.Expressions; using ExpressionReflect.Tests.Model; using FluentAssertions; @@ -35,10 +38,10 @@ public void ShouldPreEvaluate_LocalVariable() { // Arrange string str = "test"; - Expression> expresion = x => x.Firstname == str; + Expression> expression = x => x.Firstname == str; // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -50,10 +53,10 @@ public void ShouldPreEvaluate_LocalFuncWithoutParameter() { // Arrange Func func = () => "test"; - Expression> expresion = x => x.Firstname == func(); + Expression> expression = x => x.Firstname == func(); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -65,10 +68,10 @@ public void ShouldPreEvaluate_LocalFuncWithConstantParameter() { // Arrange Func func = x => "test" + x; - Expression> expresion = x => x.Firstname == func(5); + Expression> expression = x => x.Firstname == func(5); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -81,10 +84,10 @@ public void ShouldPreEvaluate_LocalFuncWithLocalVariableParameter() // Arrange Func func = x => "test" + x; int i = 5; - Expression> expresion = x => x.Firstname == func(i); + Expression> expression = x => x.Firstname == func(i); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -97,10 +100,10 @@ public void ShouldPreEvaluate_LocalFuncWithLocalFuncParameter() // Arrange Func func = x => "test" + x; Func i = () => 5; - Expression> expresion = x => x.Firstname == func(i()); + Expression> expression = x => x.Firstname == func(i()); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -111,10 +114,10 @@ public void ShouldPreEvaluate_LocalFuncWithLocalFuncParameter() public void ShouldPreEvaluate_InstanceMethodCallWithoutParameter() { // Arrange - Expression> expresion = x => x.Firstname == this.GetString(); + Expression> expression = x => x.Firstname == this.GetString(); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -125,10 +128,10 @@ public void ShouldPreEvaluate_InstanceMethodCallWithoutParameter() public void ShouldPreEvaluate_StaticMethodCallWithoutParameter() { // Arrange - Expression> expresion = x => x.Firstname == GetStringStatic(); + Expression> expression = x => x.Firstname == GetStringStatic(); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -139,10 +142,10 @@ public void ShouldPreEvaluate_StaticMethodCallWithoutParameter() public void ShouldPreEvaluate_InstanceMethodCallWithConstantParameter() { // Arrange - Expression> expresion = x => x.Firstname == this.GetString(5); + Expression> expression = x => x.Firstname == this.GetString(5); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -153,10 +156,10 @@ public void ShouldPreEvaluate_InstanceMethodCallWithConstantParameter() public void ShouldPreEvaluate_StaticMethodCallWithConstantParameter() { // Arrange - Expression> expresion = x => x.Firstname == GetStringStatic(5); + Expression> expression = x => x.Firstname == GetStringStatic(5); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -168,10 +171,10 @@ public void ShouldPreEvaluate_InstanceMethodCallWithLocalVariableParameter() { // Arrange int i = 5; - Expression> expresion = x => x.Firstname == this.GetString(i); + Expression> expression = x => x.Firstname == this.GetString(i); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -183,10 +186,10 @@ public void ShouldPreEvaluate_StaticMethodCallWithLocalVariableParameter() { // Arrange int i = 5; - Expression> expresion = x => x.Firstname == GetStringStatic(i); + Expression> expression = x => x.Firstname == GetStringStatic(i); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -198,10 +201,10 @@ public void ShouldPreEvaluate_InstanceMethodCallWithLocalFuncParameter() { // Arrange Func i = () => 5; - Expression> expresion = x => x.Firstname == this.GetString(i()); + Expression> expression = x => x.Firstname == this.GetString(i()); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert @@ -213,29 +216,46 @@ public void ShouldPreEvaluate_StaticMethodCallWithLocalFuncParameter() { // Arrange Func i = () => 5; - Expression> expresion = x => x.Firstname == GetStringStatic(i()); + Expression> expression = x => x.Firstname == GetStringStatic(i()); // Act - string expressionString = expresion.PartialEval().ToString(); + string expressionString = expression.PartialEval().ToString(); Console.WriteLine(expressionString); // Assert expressionString.Should().Be(@"x => (x.Firstname == ""test5"")"); } + //[Test] + //public void ShouldPreEvaluate_LocalFuncWithLambdaParameterParameter() + //{ + // // Arrange + // Func func = x => x; + // Expression> expression = x => x.Firstname == func(x.Lastname); + + // // Act + // string expressionString = expression.PartialEval().ToString(); + // Console.WriteLine(expressionString); + + // // Assert + // expressionString.Should().Be(@"x => (x.Firstname == func(x.Lastname))"); + //} + [Test] - public void ShouldPreEvaluate_LocalFuncWithLambdaParameterParameter() + public void ShouldPreEvaluate_LocalCollectionContains() { // Arrange - Func func = x => x; - Expression> expresion = x => x.Firstname == func(x.Lastname); + var ids = new List { 4, 5, 7 }; + Expression> expression = x => ids.Contains(x.Age); // Act - string expressionString = expresion.PartialEval().ToString(); + Expression exp = expression.PartialEval(); + exp = exp.ExpandCollection(); + string expressionString = exp.ToString(); Console.WriteLine(expressionString); // Assert - expressionString.Should().Be(@"x => (x.Firstname == func(x.Lastname))"); + expressionString.Should().Be(@"x => {4|5|7}.Contains(x.Age)"); } } } diff --git a/Source/ExpressionReflect.Tests/FuncExecutionTests.cs b/Source/ExpressionReflect.Tests/FuncExecutionTests.cs index eba06a4..7e215da 100644 --- a/Source/ExpressionReflect.Tests/FuncExecutionTests.cs +++ b/Source/ExpressionReflect.Tests/FuncExecutionTests.cs @@ -54,41 +54,41 @@ public void ShouldCreateSimpleFunc_PropertyGetter() reflectionResult.Should().Be(emitResult); } - [Test] - public void ShouldCreateSimpleFunc_StaticPropertyGetter() - { - //Arrange - Expression> expression = () => Customer.StaticProperty; - - //Act - Func emit = expression.Compile(); - Func reflection = expression.Reflect(); - - string emitResult = emit.Invoke(); - string reflectionResult = reflection.Invoke(); - - //Assert - emitResult.Should().Be("StaticProperty"); - reflectionResult.Should().Be("StaticProperty"); - } - - [Test] - public void ShouldCreateSimpleFunc_StaticField() - { - //Arrange - Expression> expression = () => Customer.StaticField; - - //Act - Func emit = expression.Compile(); - Func reflection = expression.Reflect(); - - string emitResult = emit.Invoke(); - string reflectionResult = reflection.Invoke(); - - //Assert - emitResult.Should().Be("StaticField"); - reflectionResult.Should().Be("StaticField"); - } + [Test] + public void ShouldCreateSimpleFunc_StaticPropertyGetter() + { + //Arrange + Expression> expression = () => Customer.StaticProperty; + + //Act + Func emit = expression.Compile(); + Func reflection = expression.Reflect(); + + string emitResult = emit.Invoke(); + string reflectionResult = reflection.Invoke(); + + //Assert + emitResult.Should().Be("StaticProperty"); + reflectionResult.Should().Be("StaticProperty"); + } + + [Test] + public void ShouldCreateSimpleFunc_StaticField() + { + //Arrange + Expression> expression = () => Customer.StaticField; + + //Act + Func emit = expression.Compile(); + Func reflection = expression.Reflect(); + + string emitResult = emit.Invoke(); + string reflectionResult = reflection.Invoke(); + + //Assert + emitResult.Should().Be("StaticField"); + reflectionResult.Should().Be("StaticField"); + } [Test] public void ShouldCreateSimpleFunc_PropertyGetter_MethodCall() diff --git a/Source/ExpressionReflect/ActionExtensions.cs b/Source/ExpressionReflect/ActionExtensions.cs index b2d1ed7..9b06681 100644 --- a/Source/ExpressionReflect/ActionExtensions.cs +++ b/Source/ExpressionReflect/ActionExtensions.cs @@ -2,61 +2,127 @@ { using System; using System.Linq.Expressions; + using JetBrains.Annotations; public static class ActionExtensions { + [PublicAPI] public static Action Reflect(this Expression target) { Action action = () => target.Execute(); return action; } + [PublicAPI] public static Action Reflect(this Expression> target) { Action action = a => target.Execute(a); return action; } + [PublicAPI] public static Action Reflect(this Expression> target) { Action action = (a, b) => target.Execute(a, b); return action; } + [PublicAPI] public static Action Reflect(this Expression> target) { Action action = (a, b, c) => target.Execute(a, b, c); return action; } + [PublicAPI] public static Action Reflect(this Expression> target) { Action action = (a, b, c, d) => target.Execute(a, b, c, d); return action; } + [PublicAPI] public static Action Reflect(this Expression> target) { Action action = (a, b, c, d, e) => target.Execute(a, b, c, d, e); return action; } + [PublicAPI] public static Action Reflect(this Expression> target) { Action action = (a, b, c, d, e, f) => target.Execute(a, b, c, d, e, f); return action; } + [PublicAPI] public static Action Reflect(this Expression> target) { Action action = (a, b, c, d, e, f, g) => target.Execute(a, b, c, d, e, f, g); return action; } + [PublicAPI] public static Action Reflect(this Expression> target) { Action action = (a, b, c, d, e, f, g, h) => target.Execute(a, b, c, d, e, f, g, h); return action; } + + [PublicAPI] + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e, f, g, h, i) => target.Execute(a, b, c, d, e, f, g, h, i); + return action; + } + + [PublicAPI] + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e, f, g, h, i, j) => target.Execute(a, b, c, d, e, f, g, h, i, j); + return action; + } + + [PublicAPI] + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e, f, g, h, i, j, k) => target.Execute(a, b, c, d, e, f, g, h, i, j, k); + return action; + } + + [PublicAPI] + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e, f, g, h, i, j, k, l) => target.Execute(a, b, c, d, e, f, g, h, i, j, k, l); + return action; + } + + [PublicAPI] + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e, f, g, h, i, j, k, l, m) => target.Execute(a, b, c, d, e, f, g, h, i, j, k, l, m); + return action; + } + + [PublicAPI] + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e, f, g, h, i, j, k, l, m, n) => target.Execute(a, b, c, d, e, f, g, h, i, j, k, l, m, n); + return action; + } + + [PublicAPI] + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) => target.Execute(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o); + return action; + } + + [PublicAPI] + public static Action Reflect(this Expression> target) + { + Action action = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => target.Execute(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p); + return action; + } } } \ No newline at end of file diff --git a/Source/ExpressionReflect/Evaluator.cs b/Source/ExpressionReflect/Evaluator.cs index 70588e4..598398b 100644 --- a/Source/ExpressionReflect/Evaluator.cs +++ b/Source/ExpressionReflect/Evaluator.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; + using JetBrains.Annotations; /// /// Enables the partial evaluation of queries. @@ -13,21 +14,23 @@ public static class Evaluator { /// - /// Performs evaluation & replacement of independent sub-trees. + /// Performs evaluation and replacement of independent sub-trees. /// /// The root of the expression tree. /// A new tree with sub-trees evaluated and replaced. + [PublicAPI] public static Expression PartialEval(this Expression expression) { return PartialEval(expression, Evaluator.CanBeEvaluatedLocally); } /// - /// Performs evaluation & replacement of independent sub-trees. + /// Performs evaluation and replacement of independent sub-trees. /// /// The root of the expression tree. /// A function that decides whether a given expression node can be part of the local function. /// A new tree with sub-trees evaluated and replaced. + [PublicAPI] public static Expression PartialEval(this Expression expression, Func fnCanBeEvaluated) { return new SubtreeEvaluator(new Nominator(fnCanBeEvaluated).Nominate(expression)).Eval(expression); @@ -39,7 +42,7 @@ private static bool CanBeEvaluatedLocally(Expression expression) } /// - /// Evaluates & replaces sub-trees when first candidate is reached (top-down). + /// Evaluates and replaces sub-trees when first candidate is reached (top-down). /// private class SubtreeEvaluator : ExpressionVisitor { diff --git a/Source/ExpressionReflect/ExpressionExtensions.cs b/Source/ExpressionReflect/ExpressionExtensions.cs index 9cddee5..7450ea1 100644 --- a/Source/ExpressionReflect/ExpressionExtensions.cs +++ b/Source/ExpressionReflect/ExpressionExtensions.cs @@ -1,14 +1,22 @@ namespace ExpressionReflect { using System.Linq.Expressions; + using JetBrains.Annotations; public static class ExpressionExtensions { + [PublicAPI] public static object Execute(this Expression expression, params object[] values) { ExpressionReflectionExecutor visitor = new ExpressionReflectionExecutor(expression); object result = visitor.Execute(values); return result; } + + [PublicAPI] + public static TResult Execute(this Expression expression, params object[] values) + { + return (TResult) expression.Execute(values); + } } } \ No newline at end of file diff --git a/Source/ExpressionReflect/ExpressionReflect.csproj b/Source/ExpressionReflect/ExpressionReflect.csproj index 96f6df9..f6149dc 100644 --- a/Source/ExpressionReflect/ExpressionReflect.csproj +++ b/Source/ExpressionReflect/ExpressionReflect.csproj @@ -53,12 +53,16 @@ + + + + + -