Monday, April 1, 2013

How to add data annotations to a class without changing it?

By MetadataType class
- Inherent from it, make it to be base class
- Then use metadata class to add validation data annotations in subclass
[MetadataType(typeof(ModelMetadata))]
public class Model : Base_Class {
}


internal class ModelMetadata {
    [Required]
    public string Name { get; set; }
}

No comments:

Post a Comment