Skip to content

Commit 4ac6ba1

Browse files
committed
Add the option OptionCanDeclareMultiExpressionsLambdaInSimpleExpressionEvaluate default value is true
1 parent f5f9a40 commit 4ac6ba1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,13 @@ public bool OptionNewFunctionEvaluationActive
860860
/// </summary>
861861
public bool OptionDetectExtensionMethodsOverloadsOnExtensionMethodNotFound { get; set; } = true;
862862

863+
/// <summary>
864+
/// If <c>true</c> Allow to define multi expression lambda in Expressions (not in script)<para/>
865+
/// If <c>false</c> Can only define simple expression lambda if not in script
866+
/// <para>Default value : <c>true</c></para>
867+
/// </summary>
868+
public bool OptionCanDeclareMultiExpressionsLambdaInSimpleExpressionEvaluate { get; set; } = true;
869+
863870
#endregion
864871

865872
#region Reflection flags
@@ -3096,6 +3103,8 @@ protected virtual bool GetLambdaExpression(string expression, Stack<object> stac
30963103
.Cast<Match>().ToList()
30973104
.ConvertAll(argMatch => argMatch.Value);
30983105

3106+
bool inScriptAtDeclaration = inScript;
3107+
30993108
stack.Push(new InternalDelegate((object[] args) =>
31003109
{
31013110
var vars = new Dictionary<string, object>(variables);
@@ -3112,10 +3121,10 @@ protected virtual bool GetLambdaExpression(string expression, Stack<object> stac
31123121

31133122
object result = null;
31143123

3115-
if (inScript && lambdaBody.StartsWith("{") && lambdaBody.EndsWith("}"))
3124+
if ((OptionCanDeclareMultiExpressionsLambdaInSimpleExpressionEvaluate || inScriptAtDeclaration)
3125+
&& lambdaBody.StartsWith("{") && lambdaBody.EndsWith("}"))
31163126
{
31173127
result = ScriptEvaluate(lambdaBody.Substring(1, lambdaBody.Length - 2));
3118-
inScript = true;
31193128
}
31203129
else
31213130
{

0 commit comments

Comments
 (0)