Skip to content

Commit 5c8ad16

Browse files
committed
Add runtime shim for LambdaExpression.Compile(bool)
1 parent cbb0b5c commit 5c8ad16

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
using System;
22
using System.Linq.Expressions;
3+
using System.Reflection;
34

45
namespace NHibernate.Impl
56
{
67
#if NET461
78
internal static class LambdaExpressionExtensions
89
{
9-
public static Delegate Compile(this LambdaExpression expression, bool preferInterpretation) =>
10-
expression.Compile(); //Concurrent Compile() call causes "Garbage Collector" suspend all threads too often
10+
//NET4.6.1 does not have this method exposed,
11+
//however it might be available in runtime
12+
private static readonly MethodInfo CompileWithPreference = typeof(LambdaExpression)
13+
.GetMethod("Compile", new[] { typeof(bool) });
14+
15+
public static Delegate Compile(this LambdaExpression expression, bool preferInterpretation)
16+
{
17+
if (CompileWithPreference != null)
18+
{
19+
return (Delegate) CompileWithPreference.Invoke(expression, new object[] { preferInterpretation });
20+
}
21+
22+
return expression.Compile(); //Concurrent Compile() call causes "Garbage Collector" suspend all threads too often
23+
}
1124
}
1225
#endif
1326
}

0 commit comments

Comments
 (0)