inheriting multiple metadatatypes
This seems like a simple one but I have a feeling that the Framework won't
let me do what I want it to do.
Let's say I have 3 pages - one that asks for firstname/lastname, one that
asks for phone number, and one that lets you edit both:
public class NameModel
{
public string FName {get;set;}
public string LName {get;set;}
}
public class PhoneModel
{
public string Phone { get; set;}
}
public string NamePhoneModel
{
public string FName {get;set;}
public string LName {get;set;}
public string Phone {get;set;}
}
How I'm validating these models at the moment is that i have two
interfaces INameModel and IPhoneModel which have all the validation
attributes. I use [MetadataType(typeof(INameModel))] on NameModel and
[MetadataType(typeof(IPhoneModel))] on PhoneModel.
What I really want to do is use both interfaces on NamePhoneModel so I
don't have to re-type all the validation attributes. Keep in mind this is
a simple solution, the real-world project is a lot more complicated than
this - in the example above it would be simple to inherit, but think about
that there might be additional properties on NameModel that won't exist in
NamePhoneModel, or to get more complicated, there might be a property for
Email that exists in NameModel and another page, say EmailModel
It doesn't feel like the right way to simply have to duplicate all those
rules - there must be a better/proper way??
No comments:
Post a Comment