I have been working on a problem in MVC where I was facing code duplicity issue creating View-Models. I was wondering if there is a way to create a class whose properties can refer to properties defined in another class. I just need to write the property name or just the reference. I basically need all other stuff like Annotations should automatically come over to my new class definition.
Here is what I am looking for:
let say I have a Class A having some annotations.
Class A {
[Required]
[EmailAddress]
[Display(Name = "Email ID")]
public string EmailID { get; set; }
[Required]
[Required]
[Display(Name = "Name")]
public string FName { get; set; }
}
Now I need to write a new class B referring to some properties defined in class A.
Class B {
public string EmailID; //should refer to class B so that I don't have to write annotations again
public string newproperty;
}