【发布时间】:2016-03-11 10:14:43
【问题描述】:
在我的网站中,我为每个页面使用了一个视图模型。每个视图模型仅包含属性,没有其他内容。几个页面使用同一组属性。我想做的是为每组属性创建一个类,然后在每个页面视图模型上使用相关组。
示例属性组:
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; }
}
现在,在我的视图模型中,我将拥有该页面的多个属性,并且我还想使用这些组中的一些属性。
我可以轻松继承其中一个组
public class VMMyPage : GroupCar
{
//My Bespoke Properties
}
我如何继承多个组...类似于:
public class VMMyPage : GroupCar, GroupSport, GroupFood
{
//My Bespoke Properties
}
我知道您不能在 C# 中执行此操作,但有解决方法吗?我已经阅读了几篇关于使用接口类的文章,但是没有我想要实现的确切示例?
【问题讨论】:
标签: c# inheritance model multiple-inheritance