Skip to content

Commit 04141d4

Browse files
Simplifies expression compilation.
Modifies the expression compilation process to directly return the compiled result, removing the unnecessary wrapping of the expression in a `Func<>`. This enhancement supports all delegates and prevents unnecessary casting or wrapping.
1 parent 943431c commit 04141d4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Hyperbee.Expressions/CompileExpressionExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ namespace Hyperbee.Expressions;
44

55
public static partial class ExpressionExtensions
66
{
7-
public static Func<TResult> Compile<TResult>(
8-
this Expression<Func<TResult>> expression,
7+
public static TResult Compile<TResult>(
8+
this Expression<TResult> expression,
99
IServiceProvider serviceProvider,
1010
bool preferInterpretation = false )
1111
{
1212
ArgumentNullException.ThrowIfNull( serviceProvider, nameof( serviceProvider ) );
1313

1414
var setter = new ServiceSetter( serviceProvider );
1515

16-
return setter.Visit( expression ) is Expression<Func<TResult>> replacedExpression
16+
return setter.Visit( expression ) is Expression<TResult> replacedExpression
1717
? replacedExpression.Compile( preferInterpretation )
1818
: throw new InvalidOperationException( "Failed to compile expression." );
1919
}

0 commit comments

Comments
 (0)