11/******************************************************************************************************
22 Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3- Version : 1.3.6.0
3+ Version : 1.3.6.1
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
@@ -1553,13 +1553,17 @@ private bool EvaluateInstanceCreationWithNewKeyword(string expr, string restOfEx
15531553
15541554 void Init ( object element , List < string > initArgs )
15551555 {
1556- if ( typeof ( IEnumerable ) . IsAssignableFrom ( type ) && ! typeof ( IDictionary ) . IsAssignableFrom ( type ) )
1556+ if ( typeof ( IEnumerable ) . IsAssignableFrom ( type )
1557+ && ! typeof ( IDictionary ) . IsAssignableFrom ( type )
1558+ && ! typeof ( ExpandoObject ) . IsAssignableFrom ( type ) )
15571559 {
15581560 MethodInfo methodInfo = type . GetMethod ( "Add" , BindingFlags . Public | BindingFlags . Instance ) ;
15591561
15601562 initArgs . ForEach ( subExpr => methodInfo . Invoke ( element , new object [ ] { Evaluate ( subExpr ) } ) ) ;
15611563 }
1562- else if ( typeof ( IDictionary ) . IsAssignableFrom ( type ) && initArgs . All ( subExpr => subExpr . TrimStart ( ) . StartsWith ( "{" ) ) )
1564+ else if ( typeof ( IDictionary ) . IsAssignableFrom ( type )
1565+ && initArgs . All ( subExpr => subExpr . TrimStart ( ) . StartsWith ( "{" ) )
1566+ && ! typeof ( ExpandoObject ) . IsAssignableFrom ( type ) )
15631567 {
15641568 initArgs . ForEach ( subExpr =>
15651569 {
@@ -1583,19 +1587,23 @@ void Init(object element, List<string> initArgs)
15831587 }
15841588 else
15851589 {
1586- ExpressionEvaluator initEvaluator = new ExpressionEvaluator ( new Dictionary < string , object > ( ) { { "this" , element } } ) ;
1590+ string variable = "V" + Guid . NewGuid ( ) . ToString ( ) . Replace ( "-" , "" ) ;
1591+
1592+ Variables [ variable ] = element ;
15871593
15881594 initArgs . ForEach ( subExpr =>
15891595 {
15901596 if ( subExpr . Contains ( "=" ) )
15911597 {
15921598 string trimmedSubExpr = subExpr . TrimStart ( ) ;
15931599
1594- initEvaluator . Evaluate ( $ "this { ( trimmedSubExpr . StartsWith ( "[" ) ? string . Empty : "." ) } { trimmedSubExpr } ") ;
1600+ Evaluate ( $ "{ variable } { ( trimmedSubExpr . StartsWith ( "[" ) ? string . Empty : "." ) } { trimmedSubExpr } ") ;
15951601 }
15961602 else
15971603 throw new ExpressionEvaluatorSyntaxErrorException ( $ "A '=' char is missing in [{ subExpr } ]. It is in a object initializer. It must contains one.") ;
15981604 } ) ;
1605+
1606+ Variables . Remove ( variable ) ;
15991607 }
16001608 }
16011609
0 commit comments