15

So - if there isn't particular reason why there isn't generic attributes,
I'm wondering - maybe they will be implemented?

Those would be great for ASP.NET MVC action filters.

Community
  • 1
  • 1
Arnis Lapsa
  • 45,880
  • 29
  • 115
  • 195

3 Answers3

20

I haven't seen any evidence of this in the 4.0 spec... so I believe the answer is "no".

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
8

C# 4 specification does not mention generics in attributes.

Lloyd
  • 1,324
  • 7
  • 10
1

Shame, stumbled across a case where I wanted to use this in a ValidationAttribute.

Something that can check whether a given collection is empty. In general, this could be with a generic or non generic parameter.

public override Boolean IsValid(Object value)
    {
        var v = value as ICollection<T>;

        return v.Count > 0;
    }

Would be useful if I could do this.

Jamie
  • 876
  • 1
  • 10
  • 28
  • I'd also like to combine generics and the ValidationAttribute. It would be nice if the ValidationAttribute implemented an IValidatable and inherited from Attribute. –  Mar 14 '11 at 20:38