This is not very useful idea simply because the classes has very little in common: only
System.Object
as a common base class. The answer depends on what you can do in
RunTimeMethod
. Not many. You can only call methods of
System.Object
.
It would look like this:
internal void RunTimeMethod<T>(T t) where T: new()
{
}
As a more advanced approach, you can use Reflection and find out some general purpose constructor. But it's much more robust to demand some common interface for any of the parameter classes and put it in a generic constraint.
internal interface IGenericParameterClass { }
internal class A : IGenericParameterClass { }
internal class B : IGenericParameterClass { }
internal void RunTimeMethod<T>(T t) where T: IGenericParameterClass, new()
{
}
Also, think about using classic OOP or interface-based approach. You might be trying to heavily abuse OOP in your approach. Just think about it.
Also, if you can explain the
ultimate goal of all this activity, you can get a chance to get better advice.
—SA