1
1
/******************************************************************************************************
2
2
Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3
- Version : 1.4.27 .0
3
+ Version : 1.4.28 .0
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
@@ -29,8 +29,6 @@ public partial class ExpressionEvaluator
29
29
{
30
30
#region Regex declarations
31
31
32
- protected const string primaryTypesRegexPattern = @"(?<=^|[^\p{L}_])(?<primaryType>object|string|bool[?]?|byte[?]?|char[?]?|decimal[?]?|double[?]?|short[?]?|int[?]?|long[?]?|sbyte[?]?|float[?]?|ushort[?]?|uint[?]?|ulong[?]?|void)(?=[^a-zA-Z_]|$)" ;
33
-
34
32
protected static readonly Regex varOrFunctionRegEx = new Regex ( @"^((?<sign>[+-])|(?<prefixOperator>[+][+]|--)|(?<varKeyword>var)\s+|(?<dynamicKeyword>dynamic)\s+|((?<nullConditional>[?])?(?<inObject>\.))?)(?<name>[\p{L}_](?>[\p{L}_0-9]*))(?>\s*)((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>|\?\?)?=(?![=>]))|(?<postfixOperator>([+][+]|--)(?![\p{L}_0-9]))|((?<isgeneric>[<](?>([\p{L}_](?>[\p{L}_0-9]*)|(?>\s+)|[,\.])+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
35
33
36
34
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])?" ;
@@ -40,6 +38,7 @@ public partial class ExpressionEvaluator
40
38
protected static readonly Regex stringBeginningRegex = new Regex ( "^(?<interpolated>[$])?(?<escaped>[@])?[\" ]" , RegexOptions . Compiled ) ;
41
39
protected static readonly Regex internalCharRegex = new Regex ( @"^['](\\[\\'0abfnrtv]|[^'])[']" , RegexOptions . Compiled ) ;
42
40
protected static readonly Regex indexingBeginningRegex = new Regex ( @"^[?]?\[" , RegexOptions . Compiled ) ;
41
+ protected static readonly Regex arrayTypeDetectionRegex = new Regex ( @"^(\s*(\[(?>(?>\s+)|[,])*)\])+" , RegexOptions . Compiled ) ;
43
42
protected static readonly Regex assignationOrPostFixOperatorRegex = new Regex ( @"^(?>\s*)((?<assignmentPrefix>[+\-*/%&|^]|<<|>>|\?\?)?=(?![=>])|(?<postfixOperator>([+][+]|--)(?![\p{L}_0-9])))" ) ;
44
43
protected static readonly Regex genericsDecodeRegex = new Regex ( "(?<name>[^,<>]+)(?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?" , RegexOptions . Compiled ) ;
45
44
protected static readonly Regex genericsEndOnlyOneTrim = new Regex ( @"(?>\s*)[>](?>\s*)$" , RegexOptions . Compiled ) ;
@@ -2583,6 +2582,18 @@ protected virtual Type EvaluateType(string expression,ref int i, string currentN
2583
2582
}
2584
2583
}
2585
2584
2585
+ Match arrayTypeMatch ;
2586
+
2587
+ if ( i < expression . Length && ( arrayTypeMatch = arrayTypeDetectionRegex . Match ( expression . Substring ( i ) ) ) . Success )
2588
+ {
2589
+ Type arrayType = GetTypeByFriendlyName ( staticType + arrayTypeMatch . Value ) ;
2590
+ if ( arrayType != null )
2591
+ {
2592
+ i += arrayTypeMatch . Length ;
2593
+ staticType = arrayType ;
2594
+ }
2595
+ }
2596
+
2586
2597
return staticType ;
2587
2598
}
2588
2599
@@ -3929,6 +3940,11 @@ protected virtual Type GetTypeByFriendlyName(string typeName, string genericType
3929
3940
typeName = typeName . Replace ( " " , "" ) . Replace ( "\t " , "" ) . Replace ( "\r " , "" ) . Replace ( "\n " , "" ) ;
3930
3941
genericTypes = genericTypes . Replace ( " " , "" ) . Replace ( "\t " , "" ) . Replace ( "\r " , "" ) . Replace ( "\n " , "" ) ;
3931
3942
3943
+ if ( primaryTypesDict . ContainsKey ( OptionCaseSensitiveEvaluationActive ? typeName : typeName . ToLower ( ) ) )
3944
+ {
3945
+ result = primaryTypesDict [ OptionCaseSensitiveEvaluationActive ? typeName : typeName . ToLower ( ) ] ;
3946
+ }
3947
+
3932
3948
if ( CacheTypesResolutions && ( TypesResolutionCaching ? . ContainsKey ( typeName + genericTypes ) ?? false ) )
3933
3949
{
3934
3950
result = TypesResolutionCaching [ typeName + genericTypes ] ;
@@ -3946,14 +3962,6 @@ protected virtual Type GetTypeByFriendlyName(string typeName, string genericType
3946
3962
result = Type . GetType ( typeName + formatedGenericTypes , false , ! OptionCaseSensitiveEvaluationActive ) ;
3947
3963
}
3948
3964
3949
- if ( result == null )
3950
- {
3951
- typeName = Regex . Replace ( typeName , primaryTypesRegexPattern ,
3952
- ( Match match ) => primaryTypesDict [ OptionCaseSensitiveEvaluationActive ? match . Value : match . Value . ToLower ( ) ] . ToString ( ) , optionCaseSensitiveEvaluationActive ? RegexOptions . None : RegexOptions . IgnoreCase ) ;
3953
-
3954
- result = Type . GetType ( typeName , false , ! OptionCaseSensitiveEvaluationActive ) ;
3955
- }
3956
-
3957
3965
if ( result == null )
3958
3966
{
3959
3967
result = Types . ToList ( ) . Find ( type => type . Name . Equals ( typeName , StringComparisonForCasing ) || type . FullName . StartsWith ( typeName + "," ) ) ;
0 commit comments