8000 Type.GetMethod overloads accepting a Type array to match arguments will allow parameter base classes / interfaces · Issue #9090 · dotnet/dotnet-api-docs · GitHub
[go: up one dir, main page]

Skip to content
Type.GetMethod overloads accepting a Type array to match arguments will allow parameter base classes / interfaces #9090
Open
@ohads-MSFT

Description

@ohads-MSFT

The docs describe the types parameter as follows:

An array of Type objects representing the number, order, and type of the parameters for the method to get.

This implies that the parameter types should match exactly, but that is not the case. For example, given:

class MyClass  { public void Foo (MyClass obj) { } }
class MySubClass : MyClass { 	}

The call typeof(MyClass).GetMethod("Foo", new[] { typeof(MySubClass) }) will actually match Foo (MyClass obj).
It looks like the behavior is more like "match the most specific method that can be invoked with the provided parameters".
So in the above case, since Foo (MyClass obj) can be called with a MySubClass parameter, it will also be matched.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-System.Reflectiondoc-bugProblem with the content; needs to be fixed

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0