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# - SharpSVN - How to get the previous revision? -

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

url - Querystring manipulation of email Address in PHP -