【发布时间】:2010-11-10 16:32:55
【问题描述】:
举个例子,比如..
public interface IInterface { }
public static void Insert<T>(this IList<T> list, IList<T> items) where T : IInterface
{
// ... logic
}
这很好用,但我想知道是否可以使用属性作为约束。比如……
class InsertableAttribute : Attribute
public static void Insert<T>(this IList<T> list, IList<T> items) where T : [Insertable]
{
// ... logic
}
显然这种语法不起作用,否则我不会发布问题。但我只是好奇这是否可能,以及如何做到这一点。
【问题讨论】:
-
如果实现了我会LOVE...
标签: c# generics attributes extension-methods