Given an example such as ..
public interface IInterface { }
public static void Insert<T>(this IList<T> list, IList<T> items) where T : IInterface
{
// ... logic
}
This works fine, but I was wondering if it is possible to use an Attribute as a constraint. Such as …
class InsertableAttribute : Attribute
public static void Insert<T>(this IList<T> list, IList<T> items) where T : [Insertable]
{
// ... logic
}
Obviously this syntax doesn’t work, or I wouldn’t be posting the question. But I’m just curious if it is possible or not, and how to do it.
No. You can only use (base)classes and interfaces as constraints.
You can however do something like this: