@@ -501,6 +501,7 @@ public bool OptionCaseSensitiveEvaluationActive
501
501
set
502
502
{
503
503
optionCaseSensitiveEvaluationActive = value ;
504
+ StringComparisonForCasing = optionCaseSensitiveEvaluationActive ? StringComparison . Ordinal : StringComparison . OrdinalIgnoreCase ;
504
505
Variables = Variables ;
505
506
operatorsDictionary = new Dictionary < string , ExpressionOperator > ( operatorsDictionary , StringComparerForCasing ) ;
506
507
defaultVariables = new Dictionary < string , object > ( defaultVariables , StringComparerForCasing ) ;
@@ -510,6 +511,8 @@ public bool OptionCaseSensitiveEvaluationActive
510
511
}
511
512
}
512
513
514
+ private StringComparison StringComparisonForCasing { get ; set ; } = StringComparison . Ordinal ;
515
+
513
516
private StringComparer StringComparerForCasing
514
517
{
515
518
get
@@ -903,23 +906,21 @@ object ManageJumpStatementsOrExpressionEval(string expression)
903
906
{
904
907
expression = expression . Trim ( ) ;
905
908
906
- string expressionToTest = OptionCaseSensitiveEvaluationActive ? expression : expression . ToLower ( ) ;
907
-
908
- if ( expressionToTest . Equals ( "break" ) )
909
+ if ( expression . Equals ( "break" , StringComparisonForCasing ) )
909
910
{
910
911
isBreak = true ;
911
912
return lastResult ;
912
913
}
913
914
914
- if ( expressionToTest . Equals ( "continue" ) )
915
+ if ( expression . Equals ( "continue" , StringComparisonForCasing ) )
915
916
{
916
917
isContinue = true ;
917
918
return lastResult ;
918
919
}
919
920
920
- if ( expressionToTest . StartsWith ( "throw " ) )
921
+ if ( expression . StartsWith ( "throw " , StringComparisonForCasing ) )
921
922
{
922
- throw Evaluate ( expressionToTest . Remove ( 0 , 6 ) ) as Exception ;
923
+ throw Evaluate ( expression . Remove ( 0 , 6 ) ) as Exception ;
923
924
}
924
925
925
926
expression = returnKeywordRegex . Replace ( expression , match =>
@@ -1071,9 +1072,6 @@ void ExecuteBlocksStacks()
1071
1072
if ( blockKeywordsBeginingMatch . Success )
1072
1073
i ++ ;
1073
1074
1074
- if ( ! OptionCaseSensitiveEvaluationActive )
1075
- keyword = keyword . ToLower ( ) ;
1076
-
1077
1075
Match blockBeginningMatch = blockBeginningRegex . Match ( script . Substring ( i ) ) ;
1078
1076
1079
1077
string subScript = string . Empty ;
@@ -1111,7 +1109,7 @@ void ExecuteBlocksStacks()
1111
1109
throw new ExpressionEvaluatorSyntaxErrorException ( $ "No instruction after [{ keyword } ] statement.") ;
1112
1110
}
1113
1111
1114
- if ( keyword . Equals ( "elseif" ) )
1112
+ if ( keyword . Equals ( "elseif" , StringComparisonForCasing ) )
1115
1113
{
1116
1114
if ( ifBlockEvaluatedState == IfBlockEvaluatedState . NoBlockEvaluated )
1117
1115
{
@@ -1123,7 +1121,7 @@ void ExecuteBlocksStacks()
1123
1121
ifBlockEvaluatedState = IfBlockEvaluatedState . ElseIf ;
1124
1122
}
1125
1123
}
1126
- else if ( keyword . Equals ( "else" ) )
1124
+ else if ( keyword . Equals ( "else" , StringComparisonForCasing ) )
1127
1125
{
1128
1126
if ( ifBlockEvaluatedState == IfBlockEvaluatedState . NoBlockEvaluated )
1129
1127
{
@@ -1135,7 +1133,7 @@ void ExecuteBlocksStacks()
1135
1133
ifBlockEvaluatedState = IfBlockEvaluatedState . NoBlockEvaluated ;
1136
1134
}
1137
1135
}
1138
- else if ( keyword . Equals ( "catch" ) )
1136
+ else if ( keyword . Equals ( "catch" , StringComparisonForCasing ) )
1139
1137
{
1140
1138
if ( tryBlockEvaluatedState == TryBlockEvaluatedState . NoBlockEvaluated )
1141
1139
{
@@ -1147,7 +1145,7 @@ void ExecuteBlocksStacks()
1147
1145
tryBlockEvaluatedState = TryBlockEvaluatedState . Catch ;
1148
1146
}
1149
1147
}
1150
- else if ( keyword . Equals ( "finally" ) )
1148
+ else if ( keyword . Equals ( "finally" , StringComparisonForCasing ) )
1151
1149
{
1152
1150
if ( tryBlockEvaluatedState == TryBlockEvaluatedState . NoBlockEvaluated )
1153
1151
{
@@ -1163,22 +1161,22 @@ void ExecuteBlocksStacks()
1163
1161
{
1164
1162
ExecuteBlocksStacks ( ) ;
1165
1163
1166
- if ( keyword . Equals ( "if" ) )
1164
+ if ( keyword . Equals ( "if" , StringComparisonForCasing ) )
1167
1165
{
1168
1166
ifElseStatementsList . Add ( new List < string > ( ) { keywordAttributes [ 0 ] , subScript } ) ;
1169
1167
ifBlockEvaluatedState = IfBlockEvaluatedState . If ;
1170
1168
tryBlockEvaluatedState = TryBlockEvaluatedState . NoBlockEvaluated ;
1171
1169
}
1172
- else if ( keyword . Equals ( "try" ) )
1170
+ else if ( keyword . Equals ( "try" , StringComparisonForCasing ) )
1173
1171
{
1174
1172
tryStatementsList . Add ( new List < string > ( ) { subScript } ) ;
1175
1173
ifBlockEvaluatedState = IfBlockEvaluatedState . NoBlockEvaluated ;
1176
1174
tryBlockEvaluatedState = TryBlockEvaluatedState . Try ;
1177
1175
}
1178
- else if ( keyword . Equals ( "do" ) )
1176
+ else if ( keyword . Equals ( "do" , StringComparisonForCasing ) )
1179
1177
{
1180
1178
if ( ( blockKeywordsBeginingMatch = blockKeywordsBeginningRegex . Match ( script . Substring ( i ) ) ) . Success
1181
- && blockKeywordsBeginingMatch . Groups [ "keyword" ] . Value . ManageCasing ( OptionCaseSensitiveEvaluationActive ) . Equals ( "while" ) )
1179
+ && blockKeywordsBeginingMatch . Groups [ "keyword" ] . Value . Equals ( "while" , StringComparisonForCasing ) )
1182
1180
{
1183
1181
i += blockKeywordsBeginingMatch . Length ;
1184
1182
keywordAttributes = GetExpressionsBetweenParenthesesOrOtherImbricableBrackets ( script , ref i , true , ";" ) ;
@@ -1218,7 +1216,7 @@ void ExecuteBlocksStacks()
1218
1216
throw new ExpressionEvaluatorSyntaxErrorException ( "No [while] keyword afte the [do] keyword and block" ) ;
1219
1217
}
1220
1218
}
1221
- else if ( keyword . Equals ( "while" ) )
1219
+ else if ( keyword . Equals ( "while" , StringComparisonForCasing ) )
1222
1220
{
1223
1221
while ( ! isReturn && ( bool ) ManageJumpStatementsOrExpressionEval ( keywordAttributes [ 0 ] ) )
1224
1222
{
@@ -1236,7 +1234,7 @@ void ExecuteBlocksStacks()
1236
1234
}
1237
1235
}
1238
1236
}
1239
- else if ( keyword . Equals ( "for" ) )
1237
+ else if ( keyword . Equals ( "for" , StringComparisonForCasing ) )
1240
1238
{
1241
1239
void forAction ( int index )
1242
1240
{
@@ -1260,15 +1258,15 @@ void forAction(int index)
1260
1258
}
1261
1259
}
1262
1260
}
1263
- else if ( keyword . Equals ( "foreach" ) )
1261
+ else if ( keyword . Equals ( "foreach" , StringComparisonForCasing ) )
1264
1262
{
1265
1263
Match foreachParenthisEvaluationMatch = foreachParenthisEvaluationRegex . Match ( keywordAttributes [ 0 ] ) ;
1266
1264
1267
1265
if ( ! foreachParenthisEvaluationMatch . Success )
1268
1266
{
1269
1267
throw new ExpressionEvaluatorSyntaxErrorException ( "wrong foreach syntax" ) ;
1270
1268
}
1271
- else if ( ! foreachParenthisEvaluationMatch . Groups [ "in" ] . Value . ManageCasing ( OptionCaseSensitiveEvaluationActive ) . Equals ( "in" ) )
1269
+ else if ( ! foreachParenthisEvaluationMatch . Groups [ "in" ] . Value . Equals ( "in" , StringComparisonForCasing ) )
1272
1270
{
1273
1271
throw new ExpressionEvaluatorSyntaxErrorException ( "no [in] keyword found in foreach" ) ;
1274
1272
}
@@ -2621,10 +2619,10 @@ private MethodInfo GetRealMethod(ref Type type, ref object obj, string func, Bin
2621
2619
List < object > modifiedArgs = new List < object > ( args ) ;
2622
2620
2623
2621
if ( OptionFluidPrefixingActive
2624
- && ( func . ManageCasing ( OptionCaseSensitiveEvaluationActive ) . StartsWith ( "Fluid" . ManageCasing ( OptionCaseSensitiveEvaluationActive ) )
2625
- || func . ManageCasing ( OptionCaseSensitiveEvaluationActive ) . StartsWith ( "Fluent" . ManageCasing ( OptionCaseSensitiveEvaluationActive ) ) ) )
2622
+ && ( func . StartsWith ( "Fluid" , StringComparisonForCasing )
2623
+ || func . StartsWith ( "Fluent" , StringComparisonForCasing ) ) )
2626
2624
{
2627
- methodInfo = GetRealMethod ( ref type , ref obj , func . ManageCasing ( OptionCaseSensitiveEvaluationActive ) . Substring ( func . ManageCasing ( OptionCaseSensitiveEvaluationActive ) . StartsWith ( "Fluid" . ManageCasing ( OptionCaseSensitiveEvaluationActive ) ) ? 5 : 6 ) , flag , modifiedArgs , genericsTypes ) ;
2625
+ methodInfo = GetRealMethod ( ref type , ref obj , func . Substring ( func . StartsWith ( "Fluid" , StringComparisonForCasing ) ? 5 : 6 ) , flag , modifiedArgs , genericsTypes ) ;
2628
2626
if ( methodInfo != null )
2629
2627
{
2630
2628
if ( methodInfo . ReturnType == typeof ( void ) )
@@ -2643,11 +2641,11 @@ private MethodInfo GetRealMethod(ref Type type, ref object obj, string func, Bin
2643
2641
2644
2642
if ( args . Contains ( null ) )
2645
2643
{
2646
- methodInfo = type . GetMethod ( func . ManageCasing ( OptionCaseSensitiveEvaluationActive ) , flag ) ;
2644
+ methodInfo = type . GetMethod ( func , flag ) ;
2647
2645
}
2648
2646
else
2649
2647
{
2650
- methodInfo = type . GetMethod ( func . ManageCasing ( OptionCaseSensitiveEvaluationActive ) , flag , null , args . ConvertAll ( arg => arg . GetType ( ) ) . ToArray ( ) , null ) ;
2648
+ methodInfo = type . GetMethod ( func , flag , null , args . ConvertAll ( arg => arg . GetType ( ) ) . ToArray ( ) , null ) ;
2651
2649
}
2652
2650
2653
2651
if ( methodInfo != null )
@@ -2657,7 +2655,7 @@ private MethodInfo GetRealMethod(ref Type type, ref object obj, string func, Bin
2657
2655
else
2658
2656
{
2659
2657
List < MethodInfo > methodInfos = type . GetMethods ( flag )
2660
- . Where ( m => m . Name . ManageCasing ( OptionCaseSensitiveEvaluationActive ) . Equals ( func . ManageCasing ( OptionCaseSensitiveEvaluationActive ) ) && m . GetParameters ( ) . Length == modifiedArgs . Count )
2658
+ . Where ( m => m . Name . Equals ( func , StringComparisonForCasing ) && m . GetParameters ( ) . Length == modifiedArgs . Count )
2661
2659
. ToList ( ) ;
2662
2660
2663
2661
for ( int m = 0 ; m < methodInfos . Count && methodInfo == null ; m ++ )
@@ -2762,7 +2760,7 @@ private BindingFlags DetermineInstanceOrStatic(ref Type objType, ref object obj)
2762
2760
}
2763
2761
}
2764
2762
2765
- string GetScriptBetweenCurlyBrackets ( string parentScript , ref int index )
2763
+ private string GetScriptBetweenCurlyBrackets ( string parentScript , ref int index )
2766
2764
{
2767
2765
string s ;
2768
2766
string currentScript = string . Empty ;
@@ -2908,11 +2906,11 @@ private bool DefaultFunctions(string name, List<string> args, out object result)
2908
2906
{
2909
2907
result = complexFunc ( this , args ) ;
2910
2908
}
2911
- else if ( OptionEvaluateFunctionActive && name . ManageCasing ( OptionCaseSensitiveEvaluationActive ) . Equals ( "Evaluate" . ManageCasing ( OptionCaseSensitiveEvaluationActive ) ) )
2909
+ else if ( OptionEvaluateFunctionActive && name . Equals ( "Evaluate" , StringComparisonForCasing ) )
2912
2910
{
2913
2911
result = Evaluate ( ( string ) Evaluate ( args [ 0 ] ) ) ;
2914
2912
}
2915
- else if ( OptionScriptEvaluateFunctionActive && name . ManageCasing ( OptionCaseSensitiveEvaluationActive ) . Equals ( "ScriptEvaluate" . ManageCasing ( OptionCaseSensitiveEvaluationActive ) ) )
2913
+ else if ( OptionScriptEvaluateFunctionActive && name . Equals ( "ScriptEvaluate" , StringComparisonForCasing ) )
2916
2914
{
2917
2915
result = ScriptEvaluate ( ( string ) Evaluate ( args [ 0 ] ) ) ;
2918
2916
}
@@ -2943,14 +2941,14 @@ private Type GetTypeByFriendlyName(string typeName, string genericTypes = "", bo
2943
2941
if ( result == null )
2944
2942
{
2945
2943
typeName = Regex . Replace ( typeName , primaryTypesRegexPattern ,
2946
- ( Match match ) => primaryTypesDict [ match . Value . ManageCasing ( OptionCaseSensitiveEvaluationActive ) ] . ToString ( ) , optionCaseSensitiveEvaluationActive ? RegexOptions . None : RegexOptions . IgnoreCase ) ;
2944
+ ( Match match ) => primaryTypesDict [ OptionCaseSensitiveEvaluationActive ? match . Value : match . Value . ToLower ( ) ] . ToString ( ) , optionCaseSensitiveEvaluationActive ? RegexOptions . None : RegexOptions . IgnoreCase ) ;
2947
2945
2948
2946
result = Type . GetType ( typeName , false , ! OptionCaseSensitiveEvaluationActive ) ;
2949
2947
}
2950
2948
2951
2949
if ( result == null )
2952
2950
{
2953
- result = Types . Find ( type => type . Name . ManageCasing ( OptionCaseSensitiveEvaluationActive ) . Equals ( typeName . ManageCasing ( OptionCaseSensitiveEvaluationActive ) ) ) ;
2951
+ result = Types . Find ( type => type . Name . Equals ( typeName , StringComparisonForCasing ) ) ;
2954
2952
}
2955
2953
2956
2954
for ( int a = 0 ; a < Assemblies . Count && result == null ; a ++ )
@@ -3179,18 +3177,6 @@ public TResult Func16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T1
3179
3177
#endregion
3180
3178
}
3181
3179
3182
- #region Internal extentions methods
3183
-
3184
- internal static class StringCaseManagementForExpressionEvaluatorExtension
3185
- {
3186
- public static string ManageCasing ( this string text , bool isCaseSensitive )
3187
- {
3188
- return isCaseSensitive ? text : text . ToLower ( ) ;
3189
- }
3190
- }
3191
-
3192
- #endregion
3193
-
3194
3180
#region linked enums
3195
3181
3196
3182
public enum OptionOnNoReturnKeywordFoundInScriptAction
0 commit comments