給出的例子如..使用屬性的泛型約束
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 *如果這是實現... – tenfour 2013-02-09 16:57:39