@@ -382,7 +382,7 @@ protected enum TryBlockEvaluatedState
382
382
{ "new" , ( self , args ) =>
383
383
{
384
384
List < object > cArgs = args . ConvertAll ( self . Evaluate ) ;
385
- return Activator . CreateInstance ( ( cArgs [ 0 ] as ClassOrEnumType ) . Type , cArgs . Skip ( 1 ) . ToArray ( ) ) ;
385
+ return cArgs [ 0 ] is ClassOrEnumType classOrEnumType ? Activator . CreateInstance ( classOrEnumType . Type , cArgs . Skip ( 1 ) . ToArray ( ) ) : null ;
386
386
}
387
387
} ,
388
388
{ "Round" , ( self , args ) =>
@@ -433,7 +433,7 @@ protected enum TryBlockEvaluatedState
433
433
/// Default : false
434
434
/// the cache is the static Dictionary TypesResolutionCaching (so it is shared by all instances of ExpressionEvaluator that have CacheTypesResolutions enabled)
435
435
/// </summary>
436
- public bool CacheTypesResolutions { get ; set ; } = false ;
436
+ public bool CacheTypesResolutions { get ; set ; }
437
437
438
438
/// <summary>
439
439
/// A shared cache for types resolution.
@@ -1777,17 +1777,20 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
1777
1777
MethodInfo methodInfo = GetRealMethod ( ref objType , ref obj , varFuncName , flag , oArgs , genericsTypes ) ;
1778
1778
1779
1779
// if not found check if obj is an expandoObject or similar
1780
- if ( obj is IDynamicMetaObjectProvider && obj is IDictionary < string , object > dictionaryObject && ( dictionaryObject [ varFuncName ] is InternalDelegate || dictionaryObject [ varFuncName ] is Delegate ) )
1780
+ if ( obj is IDynamicMetaObjectProvider
1781
+ && obj is IDictionary < string , object > dictionaryObject
1782
+ && ( dictionaryObject [ varFuncName ] is InternalDelegate || dictionaryObject [ varFuncName ] is Delegate ) )
1781
1783
{
1782
1784
if ( dictionaryObject [ varFuncName ] is InternalDelegate internalDelegate )
1783
1785
stack . Push ( internalDelegate ( oArgs . ToArray ( ) ) ) ;
1784
- else
1785
- stack . Push ( ( dictionaryObject [ varFuncName ] as Delegate ) . DynamicInvoke ( oArgs . ToArray ( ) ) ) ;
1786
+ else if ( dictionaryObject [ varFuncName ] is Delegate del )
1787
+ stack . Push ( del . DynamicInvoke ( oArgs . ToArray ( ) ) ) ;
1786
1788
}
1787
1789
else if ( objType . GetProperty ( varFuncName , InstanceBindingFlag ) is PropertyInfo instancePropertyInfo
1788
- && ( instancePropertyInfo . PropertyType . IsSubclassOf ( typeof ( Delegate ) ) || instancePropertyInfo . PropertyType == typeof ( Delegate ) ) )
1790
+ && ( instancePropertyInfo . PropertyType . IsSubclassOf ( typeof ( Delegate ) ) || instancePropertyInfo . PropertyType == typeof ( Delegate ) )
1791
+ && instancePropertyInfo . GetValue ( obj ) is Delegate del )
1789
1792
{
1790
- stack . Push ( ( instancePropertyInfo . GetValue ( obj ) as Delegate ) . DynamicInvoke ( oArgs . ToArray ( ) ) ) ;
1793
+ stack . Push ( del . DynamicInvoke ( oArgs . ToArray ( ) ) ) ;
1791
1794
}
1792
1795
else
1793
1796
{
@@ -1813,9 +1816,10 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
1813
1816
stack . Push ( methodInfo . Invoke ( isExtention ? null : obj , oArgs . ToArray ( ) ) ) ;
1814
1817
}
1815
1818
else if ( objType . GetProperty ( varFuncName , StaticBindingFlag ) is PropertyInfo staticPropertyInfo
1816
- && ( staticPropertyInfo . PropertyType . IsSubclassOf ( typeof ( Delegate ) ) || staticPropertyInfo . PropertyType == typeof ( Delegate ) ) )
1819
+ && ( staticPropertyInfo . PropertyType . IsSubclassOf ( typeof ( Delegate ) ) || staticPropertyInfo . PropertyType == typeof ( Delegate ) )
1820
+ && staticPropertyInfo . GetValue ( obj ) is Delegate del2 )
1817
1821
{
1818
- stack . Push ( ( staticPropertyInfo . GetValue ( obj ) as Delegate ) . DynamicInvoke ( oArgs . ToArray ( ) ) ) ;
1822
+ stack . Push ( del2 . DynamicInvoke ( oArgs . ToArray ( ) ) ) ;
1819
1823
}
1820
1824
else
1821
1825
{
0 commit comments