1
1
/******************************************************************************************************
2
2
Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3
- Version : 1.4.1.0
3
+ Version : 1.4.1.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
@@ -1735,6 +1735,7 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
1735
1735
object obj = stack . Pop ( ) ;
1736
1736
object keepObj = obj ;
1737
1737
Type objType = null ;
1738
+ Type [ ] inferedGenericsTypes = obj . GetType ( ) . GenericTypeArguments ;
1738
1739
ValueTypeNestingTrace valueTypeNestingTrace = null ;
1739
1740
1740
1741
if ( obj != null && TypesToBlock . Contains ( obj . GetType ( ) ) )
@@ -1775,7 +1776,7 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
1775
1776
throw new ExpressionEvaluatorSyntaxErrorException ( $ "[{ objType } ] object has no Method named \" { varFuncName } \" .") ;
1776
1777
1777
1778
// Standard Instance or public method find
1778
- MethodInfo methodInfo = GetRealMethod ( ref objType , ref obj , varFuncName , flag , oArgs , genericsTypes ) ;
1779
+ MethodInfo methodInfo = GetRealMethod ( ref objType , ref obj , varFuncName , flag , oArgs , genericsTypes , inferedGenericsTypes ) ;
1779
1780
1780
1781
// if not found check if obj is an expandoObject or similar
1781
1782
if ( obj is IDynamicMetaObjectProvider
@@ -1807,7 +1808,7 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
1807
1808
for ( int e = 0 ; e < StaticTypesForExtensionsMethods . Count && methodInfo == null ; e ++ )
1808
1809
{
1809
1810
Type type = StaticTypesForExtensionsMethods [ e ] ;
1810
- methodInfo = GetRealMethod ( ref type , ref extentionObj , varFuncName , StaticBindingFlag , oArgs , genericsTypes ) ;
1811
+ methodInfo = GetRealMethod ( ref type , ref extentionObj , varFuncName , StaticBindingFlag , oArgs , genericsTypes , inferedGenericsTypes ) ;
1811
1812
isExtention = methodInfo != null ;
1812
1813
}
1813
1814
}
@@ -2781,7 +2782,7 @@ protected virtual bool GetLambdaExpression(string expression, Stack<object> stac
2781
2782
}
2782
2783
}
2783
2784
2784
- protected virtual MethodInfo GetRealMethod ( ref Type type , ref object obj , string func , BindingFlags flag , List < object > args , string genericsTypes = "" )
2785
+ protected virtual MethodInfo GetRealMethod ( ref Type type , ref object obj , string func , BindingFlags flag , List < object > args , string genericsTypes , Type [ ] inferedGenericsTypes )
2785
2786
{
2786
2787
MethodInfo methodInfo = null ;
2787
2788
List < object > modifiedArgs = new List < object > ( args ) ;
@@ -2790,7 +2791,7 @@ protected virtual MethodInfo GetRealMethod(ref Type type, ref object obj, string
2790
2791
&& ( func . StartsWith ( "Fluid" , StringComparisonForCasing )
2791
2792
|| func . StartsWith ( "Fluent" , StringComparisonForCasing ) ) )
2792
2793
{
2793
- methodInfo = GetRealMethod ( ref type , ref obj , func . Substring ( func . StartsWith ( "Fluid" , StringComparisonForCasing ) ? 5 : 6 ) , flag , modifiedArgs , genericsTypes ) ;
2794
+ methodInfo = GetRealMethod ( ref type , ref obj , func . Substring ( func . StartsWith ( "Fluid" , StringComparisonForCasing ) ? 5 : 6 ) , flag , modifiedArgs , genericsTypes , inferedGenericsTypes ) ;
2794
2795
if ( methodInfo != null )
2795
2796
{
2796
2797
if ( methodInfo . ReturnType == typeof ( void ) )
@@ -2818,7 +2819,7 @@ protected virtual MethodInfo GetRealMethod(ref Type type, ref object obj, string
2818
2819
2819
2820
if ( methodInfo != null )
2820
2821
{
2821
- methodInfo = MakeConcreteMethodIfGeneric ( methodInfo , genericsTypes ) ;
2822
+ methodInfo = MakeConcreteMethodIfGeneric ( methodInfo , genericsTypes , inferedGenericsTypes ) ;
2822
2823
}
2823
2824
else
2824
2825
{
@@ -2828,7 +2829,7 @@ protected virtual MethodInfo GetRealMethod(ref Type type, ref object obj, string
2828
2829
2829
2830
for ( int m = 0 ; m < methodInfos . Count && methodInfo == null ; m ++ )
2830
2831
{
2831
- methodInfos [ m ] = MakeConcreteMethodIfGeneric ( methodInfos [ m ] , genericsTypes ) ;
2832
+ methodInfos [ m ] = MakeConcreteMethodIfGeneric ( methodInfos [ m ] , genericsTypes , inferedGenericsTypes ) ;
2832
2833
2833
2834
bool parametersCastOK = true ;
2834
2835
@@ -2891,14 +2892,25 @@ protected virtual MethodInfo GetRealMethod(ref Type type, ref object obj, string
2891
2892
return methodInfo ;
2892
2893
}
2893
2894
2894
- protected virtual MethodInfo MakeConcreteMethodIfGeneric ( MethodInfo methodInfo , string genericsTypes = "" )
2895
+ protected virtual MethodInfo MakeConcreteMethodIfGeneric ( MethodInfo methodInfo , string genericsTypes , Type [ ] inferedGenericsTypes )
2895
2896
{
2896
2897
if ( methodInfo . IsGenericMethod )
2897
2898
{
2898
2899
if ( genericsTypes . Equals ( string . Empty ) )
2899
- return methodInfo . MakeGenericMethod ( Enumerable . Repeat ( typeof ( object ) , methodInfo . GetGenericArguments ( ) . Length ) . ToArray ( ) ) ;
2900
+ {
2901
+ if ( inferedGenericsTypes != null && inferedGenericsTypes . Length == methodInfo . GetGenericArguments ( ) . Length )
2902
+ {
2903
+ return methodInfo . MakeGenericMethod ( inferedGenericsTypes ) ;
2904
+ }
2905
+ else
2906
+ {
2907
+ return methodInfo . MakeGenericMethod ( Enumerable . Repeat ( typeof ( object ) , methodInfo . GetGenericArguments ( ) . Length ) . ToArray ( ) ) ;
2908
+ }
2909
+ }
2900
2910
else
2911
+ {
2901
2912
return methodInfo . MakeGenericMethod ( GetConcreteTypes ( genericsTypes ) ) ;
2913
+ }
2902
2914
}
2903
2915
2904
2916
return methodInfo ;
0 commit comments