1
1
/******************************************************************************************************
2
2
Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3
- Version : 1.3.6.0
3
+ Version : 1.3.6.1
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
@@ -1553,13 +1553,17 @@ private bool EvaluateInstanceCreationWithNewKeyword(string expr, string restOfEx
1553
1553
1554
1554
void Init ( object element , List < string > initArgs )
1555
1555
{
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 ) )
1557
1559
{
1558
1560
MethodInfo methodInfo = type . GetMethod ( "Add" , BindingFlags . Public | BindingFlags . Instance ) ;
1559
1561
1560
1562
initArgs . ForEach ( subExpr => methodInfo . Invoke ( element , new object [ ] { Evaluate ( subExpr ) } ) ) ;
1561
1563
}
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 ) )
1563
1567
{
1564
1568
initArgs . ForEach ( subExpr =>
1565
1569
{
@@ -1583,19 +1587,23 @@ void Init(object element, List<string> initArgs)
1583
1587
}
1584
1588
else
1585
1589
{
1586
- ExpressionEvaluator initEvaluator = new ExpressionEvaluator ( new Dictionary < string , object > ( ) { { "this" , element } } ) ;
1590
+ string variable = "V" + Guid . NewGuid ( ) . ToString ( ) . Replace ( "-" , "" ) ;
1591
+
1592
+ Variables [ variable ] = element ;
1587
1593
1588
1594
initArgs . ForEach ( subExpr =>
1589
1595
{
1590
1596
if ( subExpr . Contains ( "=" ) )
1591
1597
{
1592
1598
string trimmedSubExpr = subExpr . TrimStart ( ) ;
1593
1599
1594
- initEvaluator . Evaluate ( $ "this { ( trimmedSubExpr . StartsWith ( "[" ) ? string . Empty : "." ) } { trimmedSubExpr } ") ;
1600
+ Evaluate ( $ "{ variable } { ( trimmedSubExpr . StartsWith ( "[" ) ? string . Empty : "." ) } { trimmedSubExpr } ") ;
1595
1601
}
1596
1602
else
1597
1603
throw new ExpressionEvaluatorSyntaxErrorException ( $ "A '=' char is missing in [{ subExpr } ]. It is in a object initializer. It must contains one.") ;
1598
1604
} ) ;
1605
+
1606
+ Variables . Remove ( variable ) ;
1599
1607
}
1600
1608
}
1601
1609
0 commit comments