I have a method that is passing in a object as a generic. Note that these objects do not derive from the same class. I have a function that I would like to call regardless of the type but am not able to call because it cannot determine the type.
'T' does not contain a definition for 'Validate'
And the code
public void VerifyInput<T>(T obj)
{
((T)obj).Validate();
}
This is being used to validate user data passed in. Each of the classes are responsible for setting their own validation but they are not necessarily related in any way. I have simplified this but the basic question remains. How can I cast the type of a generic to call an object method?