If I have:
void MyMethod(Object obj) { ... }
How can I cast obj to what its actual type is?
If multiple types are possible, the method itself does not know the type to cast, but the caller does, you might use something like this:
void TheObliviousHelperMethod(object obj) {
(T)obj.ThatClassMethodYouWantedToInvoke();
}
// Meanwhile, where the method is called:
TheObliviousHelperMethod(obj);
Restrictions on the type could be added using the where keyword after the parentheses.