Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

csharp attributes as generics constraints

public static void Insert<T>(this IList<T> list, IList<T> items)
{
    var attributes = typeof(T).GetCustomAttributes(typeof(InsertableAttribute), true);

    if (attributes.Length == 0)
        throw new ArgumentException("T does not have attribute InsertableAttribute");

    /// Logic.
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #csharp #attributes #generics #constraints
ADD COMMENT
Topic
Name
5+2 =