1
1
/******************************************************************************************************
2
2
Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3
- Version : 1.4.1.1
3
+ Version : 1.4.1.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
@@ -452,13 +452,18 @@ public static void ClearAllCaches()
452
452
453
453
#region Assemblies, Namespaces and types lists
454
454
455
- private static readonly IList < Assembly > assemblies = AppDomain . CurrentDomain . GetAssemblies ( ) . ToList ( ) ;
456
-
455
+ private static IList < Assembly > staticAssemblies ;
456
+ private IList < Assembly > assemblies ;
457
+
457
458
/// <summary>
458
459
/// All assemblies needed to resolves Types
459
460
/// by default all Assemblies loaded in the current AppDomain
460
461
/// </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
+ }
462
467
463
468
/// <summary>
464
469
/// All Namespaces Where to find types
@@ -850,8 +855,6 @@ public IDictionary<string, object> Variables
850
855
/// </summary>
851
856
public ExpressionEvaluator ( )
852
857
{
853
- AssembliesInit ( ) ;
854
-
855
858
DefaultDecimalSeparatorInit ( ) ;
856
859
857
860
Init ( ) ;
@@ -866,11 +869,6 @@ public ExpressionEvaluator(IDictionary<string, object> variables) : this()
866
869
Variables = variables ;
867
870
}
868
871
869
- protected virtual void AssembliesInit ( )
870
- {
871
- Assemblies = assemblies ;
872
- }
873
-
874
872
protected virtual void DefaultDecimalSeparatorInit ( )
875
873
{
876
874
numberRegexPattern = string . Format ( numberRegexOrigPattern , @"\." , string . Empty ) ;
@@ -1364,8 +1362,6 @@ void forAction(int index)
1364
1362
breakCalled = isBreak ;
1365
1363
continueCalled = isContinue ;
1366
1364
1367
- inScript = false ;
1368
-
1369
1365
if ( isReturn || OptionOnNoReturnKeywordFoundInScriptAction == OptionOnNoReturnKeywordFoundInScriptAction . ReturnAutomaticallyLastEvaluatedExpression )
1370
1366
return lastResult ;
1371
1367
else if ( OptionOnNoReturnKeywordFoundInScriptAction == OptionOnNoReturnKeywordFoundInScriptAction . ReturnNull )
@@ -2045,17 +2041,14 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
2045
2041
{
2046
2042
dictionaryObject [ varFuncName ] = varValue ;
2047
2043
}
2044
+ else if ( valueTypeNestingTrace != null )
2045
+ {
2046
+ valueTypeNestingTrace . Value = varValue ;
2047
+ valueTypeNestingTrace . AssignValue ( ) ;
2048
+ }
2048
2049
else
2049
2050
{
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 ) ;
2059
2052
}
2060
2053
}
2061
2054
}
@@ -2759,21 +2752,33 @@ protected virtual bool GetLambdaExpression(string expression, Stack<object> stac
2759
2752
2760
2753
stack . Push ( new InternalDelegate ( ( object [ ] args ) =>
2761
2754
{
2762
- Dictionary < string , object > vars = new Dictionary < string , object > ( Variables ) ;
2755
+ var vars = new Dictionary < string , object > ( variables ) ;
2763
2756
2764
2757
for ( int a = 0 ; a < argsNames . Count || a < args . Length ; a ++ )
2765
2758
{
2766
2759
vars [ argsNames [ a ] ] = args [ a ] ;
2767
2760
}
2768
2761
2769
- ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator ( vars ) ;
2762
+ var savedVars = variables ;
2763
+ Variables = vars ;
2770
2764
2771
2765
string lambdaBody = lambdaExpressionMatch . Groups [ "expression" ] . Value . Trim ( ) ;
2772
2766
2767
+ object result = null ;
2768
+
2773
2769
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
+ }
2775
2774
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 ;
2777
2782
} ) ) ;
2778
2783
2779
2784
return true ;
0 commit comments