private static MethodDesc FindMatchingVirtualMethodOnTypeByNameAndSig(MethodDesc targetMethod, DefType currentType) { string name = targetMethod.Name; MethodSignature sig = targetMethod.Signature; // TODO: InstantiatedType.GetMethod can't handle this for a situation like // an instantiation of Foo<T>.M(T) because sig is instantiated, but it compares // it to the uninstantiated version //MethodDesc implMethod = currentType.GetMethod(name, sig); MethodDesc implMethod = null; foreach (MethodDesc candidate in currentType.GetAllMethods()) { if (!candidate.IsVirtual) { continue; } if (candidate.Name == name) { if (candidate.Signature.Equals(sig)) { if (implMethod != null) { throw NotImplemented.ActiveIssue("https://github.com/dotnet/corert/issues/190"); } implMethod = candidate; } } } return(implMethod); }
/// <summary> /// Find matching a matching method by name and sig on a type. (Restricted to virtual methods only) /// </summary> /// <param name="targetMethod"></param> /// <param name="currentType"></param> /// <param name="reverseMethodSearch">Used to control the order of the search. For historical purposes to /// match .NET Framework behavior, this is typically true, but not always. There is no particular rationale /// for the particular orders other than to attempt to be consistent in virtual method override behavior /// betweeen runtimes.</param> /// <param name="nameSigMatchMethodIsValidCandidate"></param> /// <returns></returns> private static MethodDesc FindMatchingVirtualMethodOnTypeByNameAndSig(MethodDesc targetMethod, DefType currentType, bool reverseMethodSearch, Func <MethodDesc, MethodDesc, bool> nameSigMatchMethodIsValidCandidate) { string name = targetMethod.Name; MethodSignature sig = targetMethod.Signature; MethodDesc implMethod = null; foreach (MethodDesc candidate in currentType.GetAllMethods()) { if (!candidate.IsVirtual) { continue; } if (candidate.Name == name) { if (candidate.Signature.Equals(sig)) { if (nameSigMatchMethodIsValidCandidate == null || nameSigMatchMethodIsValidCandidate(targetMethod, candidate)) { implMethod = candidate; // If reverseMethodSearch is enabled, we want to find the last match on this type, not the first // (reverseMethodSearch is used for most matches except for searches for name/sig method matches for interface methods on the most derived type) if (!reverseMethodSearch) { return(implMethod); } } } } } return(implMethod); }
private static MethodDesc FindMatchingVirtualMethodOnTypeByNameAndSig(MethodDesc targetMethod, DefType currentType) { string name = targetMethod.Name; MethodSignature sig = targetMethod.Signature; // TODO: InstantiatedType.GetMethod can't handle this for a situation like // an instantiation of Foo<T>.M(T) because sig is instantiated, but it compares // it to the uninstantiated version //MethodDesc implMethod = currentType.GetMethod(name, sig); MethodDesc implMethod = null; foreach (MethodDesc candidate in currentType.GetAllMethods()) { if (!candidate.IsVirtual) { continue; } if (candidate.Name == name) { if (candidate.Signature.Equals(sig)) { if (implMethod != null) { throw new NotImplementedException("NYI: differentiating between overloads on instantiations when the instantiated signatures match."); } implMethod = candidate; } } } return(implMethod); }