Everyone knows
public class Test<T> where T : SomeBaseClass
But is there a way to restrict T
to classes that exists in a namespace like
public class Test<T> where T in SomeNamespace
Best regards
No. There's no way to constrain a generic type to a namespace.
Namespace constrains are not possible. Anyway it does not makes any sence because everyone can create classes which are located in the target namespace. It maybe would only make sence if you can restrict it to a specific assembly.
Would make more sence if you can restrict it to n
types like the following lines( doesn't work ):
public T Create<T>() where T : { MyClass1, MyClass2 }
http://msdn.microsoft.com/en-us/library/d5x73970.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With