Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serializing DataAnnotations

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.

like image 497
W3Max Avatar asked Jul 28 '26 03:07

W3Max


1 Answers

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

like image 69
jasper Avatar answered Jul 30 '26 18:07

jasper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!