@@ -35,7 +35,7 @@ public MemberInfo GetMember(string name)
3535 }
3636 if ( _nameToMember . TryGetValue ( name , out var member ) )
3737 {
38- if ( member is GenericMethod genericMethod )
38+ if ( Config . MethodMappingEnabled && member is GenericMethod genericMethod )
3939 {
4040 return genericMethod . Close ( ) ;
4141 }
@@ -79,21 +79,23 @@ void CheckPrePostfixes(MemberInfo member)
7979 }
8080 IEnumerable < MemberInfo > GetNoArgExtensionMethods ( IEnumerable < MethodInfo > sourceExtensionMethodSearch )
8181 {
82- var extensionMethods =
83- from method in sourceExtensionMethodSearch
84- where ! method . ContainsGenericParameters && method . FirstParameterType ( ) . IsAssignableFrom ( Type )
85- select ( MemberInfo ) method ;
82+ var extensionMethods = ( IEnumerable < MemberInfo > )
83+ sourceExtensionMethodSearch . Where ( method => ! method . ContainsGenericParameters && method . FirstParameterType ( ) . IsAssignableFrom ( Type ) ) ;
8684 var genericInterfaces = Type . GetInterfaces ( ) . Where ( t => t . IsGenericType ) ;
8785 if ( Type . IsInterface && Type . IsGenericType )
8886 {
8987 genericInterfaces = genericInterfaces . Prepend ( Type ) ;
9088 }
89+ if ( ! genericInterfaces . Any ( ) )
90+ {
91+ return extensionMethods ;
92+ }
9193 var definitions = genericInterfaces . GroupBy ( t => t . GetGenericTypeDefinition ( ) ) . ToDictionary ( g => g . Key , g => g . First ( ) ) ;
9294 return extensionMethods . Concat (
9395 from method in sourceExtensionMethodSearch
94- let firstParameterType = method . FirstParameterType ( )
95- where firstParameterType . IsInterface && firstParameterType . ContainsGenericParameters
96- let genericInterface = definitions . GetValueOrDefault ( firstParameterType . GetGenericTypeDefinition ( ) )
96+ let targetType = method . FirstParameterType ( )
97+ where targetType . IsInterface && targetType . ContainsGenericParameters
98+ let genericInterface = definitions . GetValueOrDefault ( targetType . GetGenericTypeDefinition ( ) )
9799 where genericInterface != null
98100 select new GenericMethod ( method , genericInterface ) ) ;
99101 }
@@ -110,23 +112,20 @@ public GenericMethod(MethodInfo genericMethod, Type genericInterface)
110112 }
111113 public MethodInfo Close ( )
112114 {
113- if ( _closedMethod ! = ExpressionBuilder . DecTypeDepthInfo )
115+ if ( _closedMethod = = ExpressionBuilder . DecTypeDepthInfo )
114116 {
115- return _closedMethod ;
116- }
117- // Use method.MakeGenericMethod(genericArguments) wrapped in a try/catch(ArgumentException)
118- // in order to catch exceptions resulting from the generic arguments not being compatible
119- // with any constraints that may be on the generic method's generic parameters.
120- try
121- {
122- _closedMethod = _genericMethod . MakeGenericMethod ( _genericInterface . GenericTypeArguments ) ;
123- }
124- catch ( ArgumentException )
125- {
126- _closedMethod = null ;
127- return null ;
117+ // Use method.MakeGenericMethod(genericArguments) wrapped in a try/catch(ArgumentException)
118+ // in order to catch exceptions resulting from the generic arguments not being compatible
119+ // with any constraints that may be on the generic method's generic parameters.
120+ try
121+ {
122+ _closedMethod = _genericMethod . MakeGenericMethod ( _genericInterface . GenericTypeArguments ) ;
123+ }
124+ catch ( ArgumentException )
125+ {
126+ _closedMethod = null ;
127+ }
128128 }
129- _closedMethod = _closedMethod . FirstParameterType ( ) . IsAssignableFrom ( _genericInterface ) ? _closedMethod : null ;
130129 return _closedMethod ;
131130 }
132131 public override Type DeclaringType => throw new NotImplementedException ( ) ;
0 commit comments