@@ -53,7 +53,7 @@ private object InvokeMethod(string name, object[] args, object[] bindArgs)
5353 private object InvokeMethod ( string name , Type [ ] typeArgs , object [ ] args , object [ ] bindArgs )
5454 {
5555 var bindResult = BindMethod ( name , typeArgs , args , bindArgs ) ;
56- if ( ( bindResult is MethodBindFailure ) && target . Flags . HasFlag ( HostTargetFlags . AllowExtensionMethods ) )
56+ if ( ( bindResult is MethodBindFailure ) && target . GetFlags ( this ) . HasFlag ( HostTargetFlags . AllowExtensionMethods ) )
5757 {
5858 var targetArg = target . Target . ToEnumerable ( ) ;
5959 var extensionArgs = targetArg . Concat ( args ) . ToArray ( ) ;
@@ -108,17 +108,17 @@ private MethodBindResult BindMethod(string name, Type[] typeArgs, object[] args,
108108 // WARNING: BindSignature holds on to the specified typeArgs; subsequent modification
109109 // will result in bugs that are difficult to diagnose. Create a copy if necessary.
110110
111- var signature = new BindSignature ( accessContext , bindFlags , target , name , typeArgs , bindArgs ) ;
111+ var signature = new BindSignature ( AccessContext , bindFlags , target , name , typeArgs , bindArgs ) ;
112112 MethodBindResult result ;
113113
114114 object rawResult ;
115115 if ( engine . TryGetCachedBindResult ( signature , out rawResult ) )
116116 {
117- result = MethodBindResult . Create ( name , rawResult , target , args ) ;
117+ result = MethodBindResult . Create ( name , bindFlags , rawResult , target , args ) ;
118118 }
119119 else
120120 {
121- result = BindMethodInternal ( accessContext , bindFlags , target , name , typeArgs , args , bindArgs ) ;
121+ result = BindMethodInternal ( AccessContext , bindFlags , target , name , typeArgs , args , bindArgs ) ;
122122 if ( ! result . IsPreferredMethod ( this , name ) )
123123 {
124124 if ( result is MethodBindSuccess )
@@ -128,7 +128,7 @@ private MethodBindResult BindMethod(string name, Type[] typeArgs, object[] args,
128128
129129 foreach ( var altName in GetAltMethodNames ( name , bindFlags ) )
130130 {
131- var altResult = BindMethodInternal ( accessContext , bindFlags , target , altName , typeArgs , args , bindArgs ) ;
131+ var altResult = BindMethodInternal ( AccessContext , bindFlags , target , altName , typeArgs , args , bindArgs ) ;
132132 if ( altResult . IsUnblockedMethod ( this ) )
133133 {
134134 result = altResult ;
@@ -163,7 +163,7 @@ private static MethodBindResult BindMethodInternal(Type bindContext, BindingFlag
163163 object rawResult ;
164164 if ( coreBindCache . TryGetValue ( signature , out rawResult ) )
165165 {
166- result = MethodBindResult . Create ( name , rawResult , target , args ) ;
166+ result = MethodBindResult . Create ( name , bindFlags , rawResult , target , args ) ;
167167 }
168168 else
169169 {
@@ -185,7 +185,7 @@ private static MethodBindResult BindMethodCore(Type bindContext, BindingFlags bi
185185 // perform default binding
186186 var rawResult = BindMethodRaw ( bindFlags , binder , target , bindArgs ) ;
187187
188- var result = MethodBindResult . Create ( name , rawResult , target , args ) ;
188+ var result = MethodBindResult . Create ( name , bindFlags , rawResult , target , args ) ;
189189 if ( ( result is MethodBindFailure ) && ! ( target is HostType ) && target . Type . IsInterface )
190190 {
191191 // binding through interface failed; try base interfaces
@@ -194,7 +194,7 @@ private static MethodBindResult BindMethodCore(Type bindContext, BindingFlags bi
194194 var baseInterfaceTarget = HostObject . Wrap ( target . InvokeTarget , interfaceType ) ;
195195 rawResult = BindMethodRaw ( bindFlags , binder , baseInterfaceTarget , bindArgs ) ;
196196
197- var baseInterfaceResult = MethodBindResult . Create ( name , rawResult , target , args ) ;
197+ var baseInterfaceResult = MethodBindResult . Create ( name , bindFlags , rawResult , target , args ) ;
198198 if ( baseInterfaceResult is MethodBindSuccess )
199199 {
200200 return baseInterfaceResult ;
@@ -205,7 +205,7 @@ private static MethodBindResult BindMethodCore(Type bindContext, BindingFlags bi
205205 var objectTarget = HostObject . Wrap ( target . InvokeTarget , typeof ( object ) ) ;
206206 rawResult = BindMethodRaw ( bindFlags , binder , objectTarget , bindArgs ) ;
207207
208- var objectResult = MethodBindResult . Create ( name , rawResult , target , args ) ;
208+ var objectResult = MethodBindResult . Create ( name , bindFlags , rawResult , target , args ) ;
209209 if ( objectResult is MethodBindSuccess )
210210 {
211211 return objectResult ;
@@ -259,7 +259,7 @@ private IEnumerable<string> GetAltMethodNames(string name, BindingFlags bindFlag
259259
260260 private IEnumerable < string > GetAltMethodNamesInternal ( string name , BindingFlags bindFlags )
261261 {
262- foreach ( var method in target . Type . GetScriptableMethods ( name , bindFlags , accessContext , defaultAccess ) )
262+ foreach ( var method in target . Type . GetScriptableMethods ( name , bindFlags , AccessContext , DefaultAccess ) )
263263 {
264264 var methodName = method . GetShortName ( ) ;
265265 if ( methodName != name )
@@ -326,7 +326,7 @@ private MethodBindResult BindMethodUsingReflection(BindingFlags bindFlags, HostT
326326 {
327327 object state ;
328328 var rawResult = Type . DefaultBinder . BindToMethod ( bindFlags , candidates , ref args , null , null , null , out state ) ;
329- return MethodBindResult . Create ( name , rawResult , hostTarget , args ) ;
329+ return MethodBindResult . Create ( name , bindFlags , rawResult , hostTarget , args ) ;
330330 }
331331 catch ( MissingMethodException )
332332 {
@@ -368,7 +368,7 @@ private IEnumerable<MethodInfo> GetReflectionCandidates(BindingFlags bindFlags,
368368
369369 private IEnumerable < MethodInfo > GetReflectionCandidates ( BindingFlags bindFlags , Type type , string name , Type [ ] typeArgs )
370370 {
371- foreach ( var method in type . GetScriptableMethods ( name , bindFlags , accessContext , defaultAccess ) )
371+ foreach ( var method in type . GetScriptableMethods ( name , bindFlags , AccessContext , DefaultAccess ) )
372372 {
373373 MethodInfo tempMethod = null ;
374374
@@ -420,12 +420,12 @@ internal static long GetCoreBindCount()
420420
421421 private abstract class MethodBindResult
422422 {
423- public static MethodBindResult Create ( string name , object rawResult , HostTarget hostTarget , object [ ] args )
423+ public static MethodBindResult Create ( string name , BindingFlags bindFlags , object rawResult , HostTarget hostTarget , object [ ] args )
424424 {
425425 var method = rawResult as MethodInfo ;
426426 if ( method != null )
427427 {
428- if ( ( method . IsStatic ) & & ! hostTarget . Flags . HasFlag ( HostTargetFlags . AllowStaticMembers ) )
428+ if ( method . IsStatic && ! bindFlags . HasFlag ( BindingFlags . Static ) )
429429 {
430430 return new MethodBindFailure ( ( ) => new InvalidOperationException ( MiscHelpers . FormatInvariant ( "Cannot access static method '{0}' in non-static context" , method . Name ) ) ) ;
431431 }
0 commit comments