c# - How to add attributes to a base class's properties -
i have couple model classes so:
public class mymodelbase { public string name { get; set; } } public class mymodel : mymodelbase { public string someotherproperty { get; set; } }
how can mymodel add [required] attribute name property?
try using metadata class. it's separate class referenced using attributes lets add data annotations model classes indirectly.
e.g.
[metadatatype(typeof(mymodelmetadata))] public class mymodel : mymodelbase { ... /* current model code */ } internal class mymodelmetadata { [required] public string name { get; set; } }
Comments
Post a Comment