【发布时间】:2014-08-20 11:04:14
【问题描述】:
是否可以将泛型类型限制为实现特定属性的类?
如果我有一个名为 MyCustomAttribute 的属性...我想写这样的东西:
public class SomeRandomClass<T>
where T : MyCustomAttribute
{
}
但不是其中 T 是 MyCustomAttribute 的派生类,而是实现该属性的类。
谢谢
编辑:
我的意思是这样实现的:
[MyCustomAttribute]
public class SomeOtherClass
{
}
【问题讨论】:
-
从类派生和实现有什么区别?
标签: c# generics custom-attributes