@@ -15,7 +15,7 @@ public class ExpressionEvaluator
1515 {
1616 #region Regex declarations
1717
18- private static Regex varOrFunctionRegEx = new Regex ( @"^((?<sign>[+-])|(?<inObject>(?<nullConditional>[?])?\.)?)(?<name>[a-zA-Z_][a-zA-Z0-9_]*)\s*((?<postfixOperator>([+][+]|--)(?![a-zA-Z0-9_]))|((?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))" , RegexOptions . IgnoreCase ) ;
18+ private static Regex varOrFunctionRegEx = new Regex ( @"^((?<sign>[+-])|(?<inObject>(?<nullConditional>[?])?\.)?)(?<name>[a-zA-Z_][a-zA-Z0-9_]*)\s*((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>]))|(?< postfixOperator>([+][+]|--)(?![a-zA-Z0-9_]))|((?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))" , RegexOptions . IgnoreCase ) ;
1919 private static Regex numberRegex = new Regex ( @"^(?<sign>[+-])?\d+(?<hasdecimal>\.?\d+(e[+-]?\d+)?)?(?<type>ul|[fdulm])?" , RegexOptions . IgnoreCase ) ;
2020 private static Regex stringBeginningRegex = new Regex ( "^(?<interpolated>[$])?(?<escaped>[@])?[\" ]" ) ;
2121 private static Regex internalCharRegex = new Regex ( @"^['](\\[']|[^'])*[']" ) ;
@@ -48,7 +48,7 @@ public class ExpressionEvaluator
4848 private static readonly Regex blockBeginningRegex = new Regex ( @"^\s*[{]" ) ;
4949 private static readonly Regex returnKeywordRegex = new Regex ( @"^return(\s+|\()" , RegexOptions . IgnoreCase | RegexOptions . Singleline ) ;
5050
51- private static readonly string tryToMatchSetPropertyRegexPattern = @"^(?<toEvaluate>([a-zA-Z_][a-zA-Z0-9_]*\s*(?<isgeneric>[(](?>[^()""]+|(?<parenthis>[(])|(?<-parenthis>[)]))*(?(parenthis) (?!))[)])*\.)+)(?<propertyToSet>[a-zA-Z_] [a-zA-Z0-9_]*)" ;
51+ // private static readonly string tryToMatchSetPropertyRegexPattern = @"^(?<toEvaluate>([a-zA-Z_][a-zA-Z0-9_]*\s*(?<isgeneric>[(](?>[^()""]+|(?<parenthis>[(])|(?<-parenthis>[)]))*(?(parenthis) (?!))[)])*\.)+)(?<propertyToSet>[a-zA-Z_] [a-zA-Z0-9_]*)";
5252
5353 #endregion
5454
@@ -1179,6 +1179,11 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
11791179
11801180 if ( varFuncMatch . Groups [ "isfunction" ] . Success )
11811181 {
1182+ //if (varFuncMatch.Groups["assignationOperator"].Success)
1183+ //{
1184+ // throw new ExpressionEvaluatorSyntaxErrorException("The left part of an assignation must be a variable, a property or an indexer");
1185+ //}
1186+
11821187 List < string > funcArgs = GetExpressionsBetweenParenthis ( expr , ref i , true ) ;
11831188 if ( varFuncMatch . Groups [ "inObject" ] . Success )
11841189 {
@@ -1337,25 +1342,48 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
13371342 BindingFlags flag = DetermineInstanceOrStatic ( ref objType , ref obj ) ;
13381343
13391344 if ( ! OptionStaticProperiesGetActive && flag . HasFlag ( BindingFlags . Static ) )
1340- throw new ExpressionEvaluatorSyntaxErrorException ( $ "[{ objType . ToString ( ) } ] object has no public Property or Member named \" { varFuncName } \" .") ;
1345+ throw new ExpressionEvaluatorSyntaxErrorException ( $ "[{ objType . ToString ( ) } ] object has no public Property or Field named \" { varFuncName } \" .") ;
13411346 if ( ! OptionInstanceProperiesGetActive && flag . HasFlag ( BindingFlags . Instance ) )
1342- throw new ExpressionEvaluatorSyntaxErrorException ( $ "[{ objType . ToString ( ) } ] object has no public Property or Member named \" { varFuncName } \" .") ;
1347+ throw new ExpressionEvaluatorSyntaxErrorException ( $ "[{ objType . ToString ( ) } ] object has no public Property or Field named \" { varFuncName } \" .") ;
1348+
1349+ dynamic member = objType ? . GetProperty ( varFuncName , flag ) ;
1350+ dynamic varValue = null ;
1351+ bool assign = true ;
1352+
13431353
1344- PropertyInfo property = objType ? . GetProperty ( varFuncName , flag ) ;
1354+ if ( member == null )
1355+ member = objType . GetField ( varFuncName , flag ) ;
1356+
1357+ varValue = member . GetValue ( obj ) ;
1358+
1359+ stack . Push ( varValue ) ;
13451360
1346- dynamic varValue = property ? . GetValue ( obj ) ;
1347- if ( varValue == null )
1361+ if ( inScript && varFuncMatch . Groups [ "assignationOperator" ] . Success )
13481362 {
1349- FieldInfo field = objType . GetField ( varFuncName , flag ) ;
1350- varValue = field . GetValue ( obj ) ;
1351- if ( varFuncMatch . Groups [ "postfixOperator" ] . Success )
1352- field . SetValue ( obj , varFuncMatch . Groups [ "postfixOperator" ] . Value . Equals ( "++" ) ? varValue + 1 : varValue - 1 ) ;
1363+ if ( stack . Count > 1 )
1364+ throw new ExpressionEvaluatorSyntaxErrorException ( ) ;
1365+
1366+ if ( ! varFuncMatch . Groups [ "assignmentPrefix" ] . Success )
1367+ {
1368+ string rightExpression = expr . Substring ( i ) ;
1369+ i = expr . Length ;
1370+
1371+ if ( rightExpression . Trim ( ) . Equals ( string . Empty ) )
1372+ throw new ExpressionEvaluatorSyntaxErrorException ( ) ;
1373+
1374+ varValue = Evaluate ( rightExpression ) ;
1375+ }
1376+
1377+ stack . Clear ( ) ;
1378+ stack . Push ( varValue ) ;
13531379 }
13541380 else if ( varFuncMatch . Groups [ "postfixOperator" ] . Success )
1355- property . SetValue ( obj , varFuncMatch . Groups [ "postfixOperator" ] . Value . Equals ( "++" ) ? varValue + 1 : varValue - 1 ) ;
1356-
1381+ varValue = varFuncMatch . Groups [ "postfixOperator" ] . Value . Equals ( "++" ) ? varValue + 1 : varValue - 1 ;
1382+ else
1383+ assign = false ;
13571384
1358- stack . Push ( varValue ) ;
1385+ if ( assign )
1386+ member . SetValue ( obj , varValue ) ;
13591387 }
13601388 }
13611389 }
0 commit comments