dotnet / dotnet/dotnet-api-docs
Type.GetMethod overloads accepting a Type array to match arguments will allow parameter base classes / interfaces
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
The docs describe the `types` parameter as follows:
> An array of [Type](https://learn.microsoft.com/en-us/dotnet/api/system.type?view=net-7.0) 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:
```cs
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.
Contributor guide
Assessment
This issue has not been assessed yet.