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
  • 42,964
  • 28
  • 114
  • 191

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
  • 976,458
  • 251
  • 2,474
  • 2,830
8

C# 4 specification does not mention generics in attributes.

Lloyd
  • 1,304
  • 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
  • 866
  • 1
  • 9
  • 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