private MethodBindResult BindMethod(string name, Type[] typeArgs, object[] args, object[] bindArgs) { var bindContext = GetEffectiveAccessContext(); var bindFlags = GetMethodBindFlags(); // WARNING: BindSignature holds on to the specified typeArgs; subsequent modification // will result in bugs that are difficult to diagnose. Create a copy if necessary. var signature = new BindSignature(bindContext, bindFlags, target, name, typeArgs, bindArgs); MethodBindResult result; object rawResult; if (engine.TryGetCachedBindResult(signature, out rawResult)) { result = MethodBindResult.Create(name, rawResult, target, args); } else { result = BindMethodInternal(bindContext, bindFlags, target, name, typeArgs, args, bindArgs); if (!result.IsPreferredMethod(name)) { if (result is MethodBindSuccess) { result = new MethodBindFailure(() => new MissingMemberException(MiscHelpers.FormatInvariant("Object has no method named '{0}' that matches the specified arguments", name))); } foreach (var altName in GetAltMethodNames(name, bindFlags)) { var altResult = BindMethodInternal(bindContext, bindFlags, target, altName, typeArgs, args, bindArgs); if (altResult.IsUnblockedMethod()) { result = altResult; break; } } } if ((result is MethodBindFailure) && engine.UseReflectionBindFallback) { var reflectionResult = BindMethodUsingReflection(bindFlags, target, name, typeArgs, args); if (reflectionResult is MethodBindSuccess) { result = reflectionResult; } } engine.CacheBindResult(signature, result.RawResult); } return(result); }
private MethodBindResult BindMethod(string name, Type[] typeArgs, object[] args, object[] bindArgs) { // WARNING: BindSignature holds on to the specified typeArgs; subsequent modification // will result in bugs that are difficult to diagnose. Create a copy if necessary. var signature = new BindSignature(target, name, typeArgs, bindArgs); MethodBindResult result; object rawResult; if (engine.TryGetCachedBindResult(signature, out rawResult)) { result = MethodBindResult.Create(name, rawResult, target, args); } else { result = BindMethodInternal(name, typeArgs, args, bindArgs); if (!result.IsPreferredMethod(name)) { if (result is MethodBindSuccess) { result = new MethodBindFailure(() => new MissingMemberException(MiscHelpers.FormatInvariant("Object has no method named '{0}' that matches the specified arguments", name))); } foreach (var altName in GetAltMethodNames(name)) { var altResult = BindMethodInternal(altName, typeArgs, args, bindArgs); if (altResult.IsUnblockedMethod()) { result = altResult; break; } } } engine.CacheBindResult(signature, result.RawResult); } return result; }