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); }
private static MethodBindResult BindMethodInternal(Type bindContext, BindingFlags bindFlags, HostTarget target, 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(bindContext, bindFlags, target, name, typeArgs, bindArgs); MethodBindResult result; object rawResult; if (coreBindCache.TryGetValue(signature, out rawResult)) { result = MethodBindResult.Create(name, rawResult, target, args); } else { result = BindMethodCore(bindContext, bindFlags, target, name, typeArgs, args, bindArgs); coreBindCache.TryAdd(signature, result.RawResult); } return(result); }
private MethodBindResult BindMethodUsingReflection(BindingFlags bindFlags, HostTarget hostTarget, string name, Type[] typeArgs, object[] args) { var candidates = GetReflectionCandidates(bindFlags, hostTarget, name, typeArgs).Distinct().ToArray(); if (candidates.Length > 0) { try { // ReSharper disable once CoVariantArrayConversion var rawResult = Type.DefaultBinder.BindToMethod(bindFlags, candidates, ref args, null, null, null, out _); return(MethodBindResult.Create(name, bindFlags, rawResult, hostTarget, args)); } catch (MissingMethodException) { } catch (AmbiguousMatchException) { } } return(new MethodBindFailure(() => new MissingMemberException(MiscHelpers.FormatInvariant("The object has no method named '{0}' that matches the specified arguments", name)))); }