We have a legacy application that has a class like this :
public class Person
{
private PersonType _type;
public PersonType GetPersonType()
{
return _type;
}
}
PersonType is a base class of several person types (User,Customer and …)
so every time we want to get the type to do something with it we should cast it like this :
var userType=(User)Person.GetPersonType();
Then I thought maybe we can have a generic overload like this :
var userType=Person.GetPersonType<User>();
So I added the overloaded method to class. Later I found out that there’s another code that uses reflection to get the first method :
var methodInfo=person.GetType().GetMethod("GetPersonType");
but since I have added this overload we are getting an ambiguous method exception.I tried to find a way to somehow distinguish the exact overload that I was looking for with no success.
So the question is how we can o get the non-generic overload info ?
(As I said it’s a legacy app built using framework 2 and we can’t use Linq and\or Extensions.)
You can tell which method is the first non-generic one like this: