In my site I use a View Model for each page. Each View Model consists of properties only, nothing else. Several of the pages use the same group of properties. What I would like to do is create a single class for each group of properties and then use the relevant groups on each pages View Model.
example property groups:
public class GroupCar
{
public string CarName { get; set; }
public string CarColour { get; set; }
public string CarLink { get; set; }
}
public class GroupSport
{
public string SportName { get; set; }
public string SportLocation { get; set; }
public string SportLink { get; set; }
}
public class GroupFood
{
public string FoodName { get; set; }
public string FoodPrice { get; set; }
public string FoodLink { get; set; }
}
Now in my View Model I would have several properties for this page and I would also like to use some properties from these groups.
I can Inherit one of the groups easily
public class VMMyPage : GroupCar
{
//My Bespoke Properties
}
How do I inherit multiple groups though...something like:
public class VMMyPage : GroupCar, GroupSport, GroupFood
{
//My Bespoke Properties
}
I know you can't do this in C# but is there a workaround? I've read several articles about using an interface class but there are no examples of exactly what I'm trying to achieve?