views:

45

answers:

2

I would like to store DataAnnotations inside a database. How can I retrieve a string representation of a DataAnnotation by reflection (or by other means)?

Example

public class Product
    {
        [DisplayName("Price")]
        [Required]
        [RegularExpression(@"^\$?\d+(\.(\d{2}))?$")]
        public decimal UnitPrice { get; set; }
    }

Result could be XML or JSON data as long as it is stringified.

+1  A: 

this is very similar to retrieve-custom-attribute-parameter-values, i'd use it as a basis for your solution

jasper
The problem is I don't know the specific type of DataAnnotation so I can't access the properties as in this example (by casting the ValidationAttribute to a specific type).
W3Max