@@ -80,7 +80,7 @@ public partial class ExpressionEvaluator
8080
8181 #region enums (Operators, if else blocks states)
8282
83- private enum ExpressionOperator
83+ protected enum ExpressionOperator
8484 {
8585 Plus ,
8686 Minus ,
@@ -129,7 +129,7 @@ private enum TryBlockEvaluatedState
129129
130130 #region Dictionaries declarations (Primary types, number suffix, escaped chars, operators management, default vars and functions)
131131
132- private static readonly Dictionary < string , Type > primaryTypesDict = new Dictionary < string , Type > ( )
132+ protected static readonly IDictionary < string , Type > primaryTypesDict = new Dictionary < string , Type > ( )
133133 {
134134 { "object" , typeof ( object ) } ,
135135 { "string" , typeof ( string ) } ,
@@ -162,7 +162,7 @@ private enum TryBlockEvaluatedState
162162 { "void" , typeof ( void ) }
163163 } ;
164164
165- private static readonly Dictionary < string , Func < string , CultureInfo , object > > numberSuffixToParse = new Dictionary < string , Func < string , CultureInfo , object > > ( StringComparer . OrdinalIgnoreCase ) // Always Case insensitive, like in C#
165+ protected static readonly IDictionary < string , Func < string , CultureInfo , object > > numberSuffixToParse = new Dictionary < string , Func < string , CultureInfo , object > > ( StringComparer . OrdinalIgnoreCase ) // Always Case insensitive, like in C#
166166 {
167167 { "f" , ( number , culture ) => float . Parse ( number , NumberStyles . Any , culture ) } ,
168168 { "d" , ( number , culture ) => double . Parse ( number , NumberStyles . Any , culture ) } ,
@@ -172,7 +172,7 @@ private enum TryBlockEvaluatedState
172172 { "m" , ( number , culture ) => decimal . Parse ( number , NumberStyles . Any , culture ) }
173173 } ;
174174
175- private static readonly Dictionary < char , string > stringEscapedCharDict = new Dictionary < char , string > ( )
175+ protected static readonly IDictionary < char , string > stringEscapedCharDict = new Dictionary < char , string > ( )
176176 {
177177 { '\\ ' , @"\" } ,
178178 { '"' , "\" " } ,
@@ -186,7 +186,7 @@ private enum TryBlockEvaluatedState
186186 { 'v' , "\v " }
187187 } ;
188188
189- private static readonly Dictionary < char , char > charEscapedCharDict = new Dictionary < char , char > ( )
189+ protected static readonly IDictionary < char , char > charEscapedCharDict = new Dictionary < char , char > ( )
190190 {
191191 { '\\ ' , '\\ ' } ,
192192 { '\' ' , '\' ' } ,
@@ -200,7 +200,7 @@ private enum TryBlockEvaluatedState
200200 { 'v' , '\v ' }
201201 } ;
202202
203- private Dictionary < string , ExpressionOperator > operatorsDictionary = new Dictionary < string , ExpressionOperator > ( StringComparer . Ordinal )
203+ protected IDictionary < string , ExpressionOperator > operatorsDictionary = new Dictionary < string , ExpressionOperator > ( StringComparer . Ordinal )
204204 {
205205 { "+" , ExpressionOperator . Plus } ,
206206 { "-" , ExpressionOperator . Minus } ,
@@ -226,18 +226,18 @@ private enum TryBlockEvaluatedState
226226 { "??" , ExpressionOperator . NullCoalescing } ,
227227 } ;
228228
229- private static readonly Dictionary < ExpressionOperator , bool > leftOperandOnlyOperatorsEvaluationDictionary = new Dictionary < ExpressionOperator , bool > ( ) ;
229+ protected static readonly IDictionary < ExpressionOperator , bool > leftOperandOnlyOperatorsEvaluationDictionary = new Dictionary < ExpressionOperator , bool > ( ) ;
230230
231- private static readonly Dictionary < ExpressionOperator , bool > rightOperandOnlyOperatorsEvaluationDictionary = new Dictionary < ExpressionOperator , bool > ( )
231+ protected static readonly IDictionary < ExpressionOperator , bool > rightOperandOnlyOperatorsEvaluationDictionary = new Dictionary < ExpressionOperator , bool > ( )
232232 {
233233 { ExpressionOperator . LogicalNegation , true } ,
234234 { ExpressionOperator . BitwiseComplement , true } ,
235235 { ExpressionOperator . UnaryPlus , true } ,
236236 { ExpressionOperator . UnaryMinus , true }
237237 } ;
238238
239- private static readonly List < Dictionary < ExpressionOperator , Func < dynamic , dynamic , object > > > operatorsEvaluations =
240- new List < Dictionary < ExpressionOperator , Func < dynamic , dynamic , object > > > ( )
239+ protected static readonly IList < IDictionary < ExpressionOperator , Func < dynamic , dynamic , object > > > operatorsEvaluations =
240+ new List < IDictionary < ExpressionOperator , Func < dynamic , dynamic , object > > > ( )
241241 {
242242 new Dictionary < ExpressionOperator , Func < dynamic , dynamic , object > > ( )
243243 {
@@ -322,7 +322,7 @@ private enum TryBlockEvaluatedState
322322 } ,
323323 } ;
324324
325- private Dictionary < string , object > defaultVariables = new Dictionary < string , object > ( StringComparer . Ordinal )
325+ protected IDictionary < string , object > defaultVariables = new Dictionary < string , object > ( StringComparer . Ordinal )
326326 {
327327 { "Pi" , Math . PI } ,
328328 { "E" , Math . E } ,
@@ -331,7 +331,7 @@ private enum TryBlockEvaluatedState
331331 { "false" , false } ,
332332 } ;
333333
334- private Dictionary < string , Func < double , double > > simpleDoubleMathFuncsDictionary = new Dictionary < string , Func < double , double > > ( StringComparer . Ordinal )
334+ protected IDictionary < string , Func < double , double > > simpleDoubleMathFuncsDictionary = new Dictionary < string , Func < double , double > > ( StringComparer . Ordinal )
335335 {
336336 { "Abs" , Math . Abs } ,
337337 { "Acos" , Math . Acos } ,
@@ -351,15 +351,15 @@ private enum TryBlockEvaluatedState
351351 { "Truncate" , Math . Truncate } ,
352352 } ;
353353
354- private Dictionary < string , Func < double , double , double > > doubleDoubleMathFuncsDictionary = new Dictionary < string , Func < double , double , double > > ( StringComparer . Ordinal )
354+ protected IDictionary < string , Func < double , double , double > > doubleDoubleMathFuncsDictionary = new Dictionary < string , Func < double , double , double > > ( StringComparer . Ordinal )
355355 {
356356 { "Atan2" , Math . Atan2 } ,
357357 { "IEEERemainder" , Math . IEEERemainder } ,
358358 { "Log" , Math . Log } ,
359359 { "Pow" , Math . Pow } ,
360360 } ;
361361
362- private Dictionary < string , Func < ExpressionEvaluator , List < string > , object > > complexStandardFuncsDictionary = new Dictionary < string , Func < ExpressionEvaluator , List < string > , object > > ( StringComparer . Ordinal )
362+ protected IDictionary < string , Func < ExpressionEvaluator , List < string > , object > > complexStandardFuncsDictionary = new Dictionary < string , Func < ExpressionEvaluator , List < string > , object > > ( StringComparer . Ordinal )
363363 {
364364 { "Array" , ( self , args ) => args . ConvertAll ( arg => self . Evaluate ( arg ) ) . ToArray ( ) } ,
365365 { "ArrayOfType" , ( self , args ) =>
@@ -480,12 +480,12 @@ public static void ClearAllCaches()
480480 /// All assemblies needed to resolves Types
481481 /// by default all Assemblies loaded in the current AppDomain
482482 /// </summary>
483- public List < Assembly > Assemblies { get ; set ; } = new List < Assembly > ( ) ;
483+ public virtual IList < Assembly > Assemblies { get ; set ; } = new List < Assembly > ( ) ;
484484
485485 /// <summary>
486486 /// All Namespaces Where to find types
487487 /// </summary>
488- public List < string > Namespaces { get ; set ; } = new List < string > ( )
488+ public virtual IList < string > Namespaces { get ; set ; } = new List < string > ( )
489489 {
490490 "System" ,
491491 "System.Linq" ,
@@ -503,17 +503,17 @@ public static void ClearAllCaches()
503503 /// <summary>
504504 /// To add or remove specific types to manage in expression.
505505 /// </summary>
506- public List < Type > Types { get ; set ; } = new List < Type > ( ) ;
506+ public virtual IList < Type > Types { get ; set ; } = new List < Type > ( ) ;
507507
508508 /// <summary>
509509 /// A list of type to block an keep un usable in Expression Evaluation for security purpose
510510 /// </summary>
511- public List < Type > TypesToBlock { get ; set ; } = new List < Type > ( ) ;
511+ public virtual IList < Type > TypesToBlock { get ; set ; } = new List < Type > ( ) ;
512512
513513 /// <summary>
514514 /// A list of statics types where to find extensions methods
515515 /// </summary>
516- public List < Type > StaticTypesForExtensionsMethods { get ; set ; } = new List < Type > ( )
516+ public virtual IList < Type > StaticTypesForExtensionsMethods { get ; set ; } = new List < Type > ( )
517517 {
518518 typeof ( Enumerable ) // For Linq extension methods
519519 } ;
@@ -872,7 +872,7 @@ public IDictionary<string, object> Variables
872872 /// </summary>
873873 public ExpressionEvaluator ( )
874874 {
875- Assemblies . AddRange ( AppDomain . CurrentDomain . GetAssemblies ( ) ) ;
875+ Assemblies = AppDomain . CurrentDomain . GetAssemblies ( ) . ToList ( ) ;
876876
877877 numberRegexPattern = string . Format ( numberRegexOrigPattern , @"\." , string . Empty ) ;
878878
@@ -2047,7 +2047,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
20472047 {
20482048 ExpressionOperator op = operatorsDictionary [ varFuncMatch . Groups [ "assignmentPrefix" ] . Value ] ;
20492049
2050- varValue = operatorsEvaluations . Find ( dict => dict . ContainsKey ( op ) ) [ op ] ( varValue , Evaluate ( rightExpression ) ) ;
2050+ varValue = operatorsEvaluations . ToList ( ) . Find ( dict => dict . ContainsKey ( op ) ) [ op ] ( varValue , Evaluate ( rightExpression ) ) ;
20512051 }
20522052 else
20532053 {
@@ -2155,7 +2155,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
21552155
21562156 ExpressionOperator op = operatorsDictionary [ varFuncMatch . Groups [ "assignmentPrefix" ] . Value ] ;
21572157
2158- cusVarValueToPush = operatorsEvaluations . Find ( dict => dict . ContainsKey ( op ) ) [ op ] ( cusVarValueToPush , Evaluate ( rightExpression ) ) ;
2158+ cusVarValueToPush = operatorsEvaluations . ToList ( ) . Find ( dict => dict . ContainsKey ( op ) ) [ op ] ( cusVarValueToPush , Evaluate ( rightExpression ) ) ;
21592159 }
21602160 else
21612161 {
@@ -2471,7 +2471,7 @@ private bool EvaluateIndexing(string expr, string s, Stack<object> stack, ref in
24712471
24722472 valueToPush = operatorsEvaluations [ 0 ] [ op ] ( left , right ) ;
24732473
2474- valueToPush = operatorsEvaluations . Find ( dict => dict . ContainsKey ( prefixOp ) ) [ prefixOp ] ( valueToPush , Evaluate ( rightExpression ) ) ;
2474+ valueToPush = operatorsEvaluations . ToList ( ) . Find ( dict => dict . ContainsKey ( prefixOp ) ) [ prefixOp ] ( valueToPush , Evaluate ( rightExpression ) ) ;
24752475 }
24762476 else
24772477 {
@@ -2635,7 +2635,7 @@ private object ProcessStack(Stack<object> stack)
26352635 . Select ( e => e is ValueTypeNestingTrace valueTypeNestingTrace ? valueTypeNestingTrace . Value : e )
26362636 . ToList ( ) ;
26372637
2638- operatorsEvaluations . ForEach ( ( Dictionary < ExpressionOperator , Func < dynamic , dynamic , object > > operatorEvalutationsDict ) =>
2638+ operatorsEvaluations . ToList ( ) . ForEach ( ( IDictionary < ExpressionOperator , Func < dynamic , dynamic , object > > operatorEvalutationsDict ) =>
26392639 {
26402640 for ( int i = list . Count - 1 ; i >= 0 ; i -- )
26412641 {
@@ -3114,7 +3114,7 @@ private Type GetTypeByFriendlyName(string typeName, string genericTypes = "", bo
31143114
31153115 if ( result == null )
31163116 {
3117- result = Types . Find ( type => type . Name . Equals ( typeName , StringComparisonForCasing ) ) ;
3117+ result = Types . ToList ( ) . Find ( type => type . Name . Equals ( typeName , StringComparisonForCasing ) ) ;
31183118 }
31193119
31203120 for ( int a = 0 ; a < Assemblies . Count && result == null ; a ++ )
0 commit comments