I know you can write:
class GenericClass<T> where T : new()
{
}
to enforce that T
has an empty constructor.
My Qs are :
can you enforce that
T
has a constructor with a specific type of parameter? Like:class SingletonFactoryWithEmptyConstructor<T> where T : new(int)
can you enforce that
T
has a static function (let's say,void F()
) so that you can use this function inside the generic class? Like :class GenericClass<T> where T : void F() { void G () { T.F(); } }
I know you can specify that
T
implements an interface but I don't want that. I want to specify thatT
has a static function.