Hi,
Is there a way to create a Generic Method that uses the new() Constraint and only accepts constructors of a given type?
Example:
I have the following code:
public T MyGenericMethod<T>(MyClass c) where T : class
{
if (typeof(T).GetConstructor(new Type[] { typeof(MyClass) }) == null)
{
throw new ArgumentException("Invalid class.");
}
// ...
}
Is it possible to have something like this instead?
public T MyGenericMethod<T>(MyClass c) where T : new(MyClass) { /* ... */ }