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

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -