Search code examples
c#attributesdeclarative

What are the advantages of attribute based programming?


I am working with WCF RIA services and have come across a sample using attributes:

[StringLength(10, ErrorMessage="Too long")]
public string FirstName { get; set; }
...

While attributes aren't restricted to WCF RIA, it reminded me of a question: why is declarative or attribute based programming perferable to coding a validation routine "the old fashioned way" ?

Thanks,

Scott


Solution

  • Because the constraint is discoverable without having to execute the code. With reflection you can access these constraints.