Skip to content

Commit b9b7498

Browse files
committed
Adding OptionIndexingAssignationActive
1 parent 57279fc commit b9b7498

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,13 @@ public bool OptionNewFunctionEvaluationActive
546546
/// By default : true
547547
/// </summary>
548548
public bool OptionPropertyOrFieldSetActive { get; set; } = true;
549+
550+
/// <summary>
551+
/// If <c>true</c> allow to assign a indexed element like Collections, List, Arrays and Dictionaries with (=, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=, ++ or --)
552+
/// If <c>false</c> unactive this functionality
553+
/// By default : true
554+
/// </summary>
555+
public bool OptionIndexingAssignationActive { get; set; } = true;
549556

550557
/// <summary>
551558
/// If <c>true</c> ScriptEvaluate function is callables in an expression. If <c>false</c> Evaluate is not callable.
@@ -1642,24 +1649,24 @@ private bool EvaluateIndexing(string expr, string s, Stack<object> stack, ref in
16421649
ExpressionOperator op = indexingBeginningMatch.Length == 2 ? ExpressionOperator.IndexingWithNullConditional : ExpressionOperator.Indexing;
16431650
dynamic left = stack.Pop();
16441651

1645-
Match assignationOrPostFixOperatorMatch = assignationOrPostFixOperatorRegex.Match(expr.Substring(i + 1));
1652+
Match assignationOrPostFixOperatorMatch = null;
16461653

16471654
object valueToPush = null;
16481655

1649-
if (assignationOrPostFixOperatorMatch.Success)
1656+
if (OptionIndexingAssignationActive && (assignationOrPostFixOperatorMatch = assignationOrPostFixOperatorRegex.Match(expr.Substring(i + 1))).Success)
16501657
{
16511658
i += assignationOrPostFixOperatorMatch.Length + 1;
16521659

1653-
bool postFixoperator = assignationOrPostFixOperatorMatch.Groups["postfixOperator"].Success;
1654-
string exceptionContext = postFixoperator ? "++ or -- operator" : "an assignation";
1660+
bool postFixOperator = assignationOrPostFixOperatorMatch.Groups["postfixOperator"].Success;
1661+
string exceptionContext = postFixOperator ? "++ or -- operator" : "an assignation";
16551662

16561663
if (stack.Count > 1)
16571664
throw new ExpressionEvaluatorSyntaxErrorException($"The left part of {exceptionContext} must be a variable, a property or an indexer.");
16581665

16591666
if (op == ExpressionOperator.IndexingWithNullConditional)
16601667
throw new ExpressionEvaluatorSyntaxErrorException($"Null coalescing is not usable left to {exceptionContext}");
16611668

1662-
if (postFixoperator)
1669+
if (postFixOperator)
16631670
valueToPush = assignationOrPostFixOperatorMatch.Groups["postfixOperator"].Value.Equals("++") ? left[right]++ : left[right]--;
16641671
else
16651672
{

0 commit comments

Comments
 (0)