Repository navigation
Resolve overloads in TryFindMethod and search inherited interfaces [patch] - #161
Merged
Merged
Conversation
…faces TryFindMethod threw AmbiguousMatchException for any overloaded name, and returned false for methods an interface inherits from its base interfaces. It now searches one hierarchy level at a time, takes the overload with the fewest parameters (non-generic first, then ordinal signature order), and for an interface also searches its inherited interfaces, most-derived first. Fixes #155 Fixes #158 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P2fpLkFHYU6nd3JVKufVtK
|
This was referenced Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #155
Fixes #158
What changes
The triage on both issues says to fix them together, so this PR does that.
TryFindMethodnow searches one hierarchy level at a time, usingGetMethods(flags | DeclaredOnly)filtered by name, and stops at the first level that declares the name.AmbiguousMatchException, and it gives the same answer every time for the same type. The rule is documented in the XML<remarks>.typeof(IList<int>).TryFindMethod("Add", …)finds nothing #158): whentypeis an interface, the search covers the interface itself and thentype.GetInterfaces(). Inherited interfaces are grouped by how many interfaces they themselves inherit, and the larger groups are searched first, so a derived interface always comes before the interfaces it extends. For example,IList<int>.GetEnumeratorresolves toIEnumerable<int>, not the non-genericIEnumerable.Tests
TryFindMethodThrowsOnAmbiguousMatchForOverloadedMethodtest asserted the bug, so it now checks that the parameterless overload is returned.string.Split, private overloads on a base class, determinism, one and two levels of interface inheritance, and theIList<int>/ICollection<int>cases from TryFindMethod returns false for methods an interface inherits from its base interfaces:typeof(IList<int>).TryFindMethod("Add", …)finds nothing #158.🤖 Generated with Claude Code
https://claude.ai/code/session_01P2fpLkFHYU6nd3JVKufVtK
Generated by Claude Code