Data serialization

I would like to store DataAnnotations inside the database. How can I get a string representation of a DataAnnotation by reflection (or in other ways)?

Example

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

The result may be XML or JSON data, if built.

+3
source share
2 answers

this is very similar to retrieve-custom-attribute-parameter-values , I would use it as the basis for your solution

+1
source

Source: https://habr.com/ru/post/1772389/


All Articles