我想创建一个像这样的签名的通用函数:void funcName<T>()
其中T
将被要求是我想要的某个特定接口的实现。如何做这样的检查?如何传递给实现certan接口的通用函数类类型?如何传递给实现certan接口的通用函数类类型?
所以我创造一些public interface IofMine {}
,我尝试创建一个功能类似public static void funcName<T>() where T : IofMine { var a = new T}
和可悲的是,我得到:
Error: Cannot create an instance of the variable type 'T' because it does not have the new() constraint
我该怎么做才能让类的类型我的功能不仅接收是我想要的界面,而且还有一个构造函数?