|
1 | 1 | /****************************************************************************************************** |
2 | 2 | Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator) |
3 | | - Version : 1.4.2.1 |
| 3 | + Version : 1.4.2.2 |
4 | 4 | (if last digit (the forth) is not a zero, the version is an intermediate version and can be unstable) |
5 | 5 |
|
6 | 6 | Author : Coding Seb |
@@ -33,7 +33,7 @@ public partial class ExpressionEvaluator |
33 | 33 | protected const string primaryTypesGroupPattern = "(?<primaryType>object|string|bool[?]?|byte[?]?|char[?]?|decimal[?]?|double[?]?|short[?]?|int[?]?|long[?]?|sbyte[?]?|float[?]?|ushort[?]?|uint[?]?|ulong[?]?|void)"; |
34 | 34 | protected const string primaryTypesRegexPattern = "(?<=^|[^" + diactiticsKeywordsRegexPattern + "])" + primaryTypesGroupPattern + "(?=[^a-zA-Z_]|$)"; |
35 | 35 |
|
36 | | - protected static readonly Regex varOrFunctionRegEx = new Regex($@"^((?<sign>[+-])|(?<prefixOperator>[+][+]|--)|(?<varKeyword>var)\s+|(?<dynamicKeyword>dynamic)\s+|{primaryTypesGroupPattern}\s+|(?<inObject>(?<nullConditional>[?])?\.)?)(?<name>[{ diactiticsKeywordsRegexPattern }](?>[{ diactiticsKeywordsRegexPattern }0-9]*))(?>\s*)((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>]))|(?<postfixOperator>([+][+]|--)(?![{ diactiticsKeywordsRegexPattern}0-9]))|((?<isgeneric>[<](?>([{ diactiticsKeywordsRegexPattern }](?>[{ diactiticsKeywordsRegexPattern }0-9]*)|(?>\s+)|[,\.])+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))", RegexOptions.IgnoreCase | RegexOptions.Compiled); |
| 36 | + protected static readonly Regex varOrFunctionRegEx = new Regex($@"^((?<sign>[+-])|(?<prefixOperator>[+][+]|--)|(?<varKeyword>var)\s+|(?<dynamicKeyword>dynamic)\s+|(?<inObject>(?<nullConditional>[?])?\.)?)(?<name>[{ diactiticsKeywordsRegexPattern }](?>[{ diactiticsKeywordsRegexPattern }0-9]*))(?>\s*)((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>]))|(?<postfixOperator>([+][+]|--)(?![{ diactiticsKeywordsRegexPattern}0-9]))|((?<isgeneric>[<](?>([{ diactiticsKeywordsRegexPattern }](?>[{ diactiticsKeywordsRegexPattern }0-9]*)|(?>\s+)|[,\.])+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))", RegexOptions.IgnoreCase | RegexOptions.Compiled); |
37 | 37 |
|
38 | 38 | protected const string numberRegexOrigPattern = @"^(?<sign>[+-])?([0-9][0-9_{1}]*[0-9]|\d)(?<hasdecimal>{0}?([0-9][0-9_]*[0-9]|\d)(e[+-]?([0-9][0-9_]*[0-9]|\d))?)?(?<type>ul|[fdulm])?"; |
39 | 39 | protected string numberRegexPattern = null; |
@@ -2117,6 +2117,19 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack, |
2117 | 2117 | else if ((Variables.TryGetValue(varFuncName, out object cusVarValueToPush) || varFuncMatch.Groups["assignationOperator"].Success) |
2118 | 2118 | && (cusVarValueToPush == null || !TypesToBlock.Contains(cusVarValueToPush.GetType()))) |
2119 | 2119 | { |
| 2120 | + StronglyTypedVariable stronglyTypedVariable; |
| 2121 | + |
| 2122 | + if (stack.Count == 1 && stack.Peek() is ClassOrEnumType classOrEnum && varFuncMatch.Groups["assignationOperator"].Success) |
| 2123 | + { |
| 2124 | + stack.Pop(); |
| 2125 | + |
| 2126 | + stronglyTypedVariable = new StronglyTypedVariable |
| 2127 | + { |
| 2128 | + Type = classOrEnum.Type, |
| 2129 | + Value = !varFuncMatch.Groups["assignationOperator"].Success && classOrEnum.Type.IsValueType ? Activator.CreateInstance(classOrEnum.Type) : null, |
| 2130 | + }; |
| 2131 | + } |
| 2132 | + |
2120 | 2133 | stack.Push(cusVarValueToPush); |
2121 | 2134 |
|
2122 | 2135 | if (OptionVariableAssignationActive) |
@@ -3599,6 +3612,13 @@ public partial class ClassOrEnumType |
3599 | 3612 | public Type Type { get; set; } |
3600 | 3613 | } |
3601 | 3614 |
|
| 3615 | + public partial class StronglyTypedVariable |
| 3616 | + { |
| 3617 | + public Type Type { get; set; } |
| 3618 | + |
| 3619 | + public object Value { get; set; } |
| 3620 | + } |
| 3621 | + |
3602 | 3622 | public partial class ExpressionEvaluatorSyntaxErrorException : Exception |
3603 | 3623 | { |
3604 | 3624 | public ExpressionEvaluatorSyntaxErrorException() : base() |
|
0 commit comments