Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 18
    You could do [Validates(typeof(string)] - I agree generics would be nicer... Commented Mar 1, 2010 at 19:43
  • 22
    Even though this is a very late addition to this question, it's sad that not only attributes themselves but also abstract attribute classes (which obviously cannot be instantiated as attributes anyways) aren't allwed, like this: abstract class Base<T>: Attribute {} which could be used to create non-generic derived classes like this: class Concrete: Base<MyType> {} Commented May 19, 2010 at 18:46
  • 97
    I crave for generic attributes and attributes accepting lambdas. Imagine things like [DependsOnProperty<Foo>(f => f.Bar)] or [ForeignKey<Foo>(f => f.IdBar)]... Commented Aug 10, 2011 at 19:39
  • 3
    This would be extremely useful in a situation I just encountered; it would be nice to create a LinkedValueAttribute that accepted a generic type and enforced that type on the actual value specified. I could use it for enums to specify the "default" value of another enum that should be used if this enum value is chosen. Multiple of these attributes could be specified for different types, and I could get the value I need based on the type I need. I can set it up to use Type and Object but being strongly typed would be a huge plus. Commented Aug 22, 2012 at 18:42
  • 10
    If you don't mind a little IL, this looks promising. Commented Oct 9, 2012 at 18:39