11/******************************************************************************************************
22 Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3- Version : 1.4.1.1
3+ Version : 1.4.1.2
44 (if last digit (the forth) is not a zero, the version is an intermediate version and can be unstable)
55
66 Author : Coding Seb
@@ -452,13 +452,18 @@ public static void ClearAllCaches()
452452
453453 #region Assemblies, Namespaces and types lists
454454
455- private static readonly IList < Assembly > assemblies = AppDomain . CurrentDomain . GetAssemblies ( ) . ToList ( ) ;
456-
455+ private static IList < Assembly > staticAssemblies ;
456+ private IList < Assembly > assemblies ;
457+
457458 /// <summary>
458459 /// All assemblies needed to resolves Types
459460 /// by default all Assemblies loaded in the current AppDomain
460461 /// </summary>
461- public virtual IList < Assembly > Assemblies { get ; set ; } = new List < Assembly > ( ) ;
462+ public virtual IList < Assembly > Assemblies
463+ {
464+ get { return assemblies ?? ( assemblies = staticAssemblies ) ?? ( assemblies = staticAssemblies = AppDomain . CurrentDomain . GetAssemblies ( ) . ToList ( ) ) ; }
465+ set { assemblies = value ; }
466+ }
462467
463468 /// <summary>
464469 /// All Namespaces Where to find types
@@ -850,8 +855,6 @@ public IDictionary<string, object> Variables
850855 /// </summary>
851856 public ExpressionEvaluator ( )
852857 {
853- AssembliesInit ( ) ;
854-
855858 DefaultDecimalSeparatorInit ( ) ;
856859
857860 Init ( ) ;
@@ -866,11 +869,6 @@ public ExpressionEvaluator(IDictionary<string, object> variables) : this()
866869 Variables = variables ;
867870 }
868871
869- protected virtual void AssembliesInit ( )
870- {
871- Assemblies = assemblies ;
872- }
873-
874872 protected virtual void DefaultDecimalSeparatorInit ( )
875873 {
876874 numberRegexPattern = string . Format ( numberRegexOrigPattern , @"\." , string . Empty ) ;
@@ -1364,8 +1362,6 @@ void forAction(int index)
13641362 breakCalled = isBreak ;
13651363 continueCalled = isContinue ;
13661364
1367- inScript = false ;
1368-
13691365 if ( isReturn || OptionOnNoReturnKeywordFoundInScriptAction == OptionOnNoReturnKeywordFoundInScriptAction . ReturnAutomaticallyLastEvaluatedExpression )
13701366 return lastResult ;
13711367 else if ( OptionOnNoReturnKeywordFoundInScriptAction == OptionOnNoReturnKeywordFoundInScriptAction . ReturnNull )
@@ -2045,17 +2041,14 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
20452041 {
20462042 dictionaryObject [ varFuncName ] = varValue ;
20472043 }
2044+ else if ( valueTypeNestingTrace != null )
2045+ {
2046+ valueTypeNestingTrace . Value = varValue ;
2047+ valueTypeNestingTrace . AssignValue ( ) ;
2048+ }
20482049 else
20492050 {
2050- if ( valueTypeNestingTrace != null )
2051- {
2052- valueTypeNestingTrace . Value = varValue ;
2053- valueTypeNestingTrace . AssignValue ( ) ;
2054- }
2055- else
2056- {
2057- ( ( dynamic ) member ) . SetValue ( obj , varValue ) ;
2058- }
2051+ ( ( dynamic ) member ) . SetValue ( obj , varValue ) ;
20592052 }
20602053 }
20612054 }
@@ -2759,21 +2752,33 @@ protected virtual bool GetLambdaExpression(string expression, Stack<object> stac
27592752
27602753 stack . Push ( new InternalDelegate ( ( object [ ] args ) =>
27612754 {
2762- Dictionary < string , object > vars = new Dictionary < string , object > ( Variables ) ;
2755+ var vars = new Dictionary < string , object > ( variables ) ;
27632756
27642757 for ( int a = 0 ; a < argsNames . Count || a < args . Length ; a ++ )
27652758 {
27662759 vars [ argsNames [ a ] ] = args [ a ] ;
27672760 }
27682761
2769- ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator ( vars ) ;
2762+ var savedVars = variables ;
2763+ Variables = vars ;
27702764
27712765 string lambdaBody = lambdaExpressionMatch . Groups [ "expression" ] . Value . Trim ( ) ;
27722766
2767+ object result = null ;
2768+
27732769 if ( inScript && lambdaBody . StartsWith ( "{" ) && lambdaBody . EndsWith ( "}" ) )
2774- return expressionEvaluator . ScriptEvaluate ( lambdaBody . Substring ( 1 , lambdaBody . Length - 2 ) ) ;
2770+ {
2771+ result = ScriptEvaluate ( lambdaBody . Substring ( 1 , lambdaBody . Length - 2 ) ) ;
2772+ inScript = true ;
2773+ }
27752774 else
2776- return expressionEvaluator . Evaluate ( lambdaExpressionMatch . Groups [ "expression" ] . Value ) ;
2775+ {
2776+ result = Evaluate ( lambdaExpressionMatch . Groups [ "expression" ] . Value ) ;
2777+ }
2778+
2779+ variables = savedVars ;
2780+
2781+ return result ;
27772782 } ) ) ;
27782783
27792784 return true ;
0 commit comments