我有一种情况,我映射具有继承层次结构的类。我有一个每个班级都知道它需要的项目清单。例如:什么是从C#中的子类中聚合属性的优雅方法?
public class PersonMapper
{
private string[] attributes = new[] {"firstName", "lastName"};
}
public class UserMapper : PersonMapper
{
private string[] attributes = new[] {"username"};
}
public class EmployeeMapper : PersonMapper
{
private string[] attributes = new[] {"employeeId"};
}
我想就返回所有的超类的这样的聚合方法调用:
EmployeeMapper mapper = new EmployeeMapper();
string[] attributes = mapper.GetAttributes();
Assert.That(attributes, Has.Member("firstname"));
我能想到的一些解决方案,但他们似乎过于复杂。我觉得我缺少一个优雅的解决方案。谁能帮忙?
在此先感谢!
接受4分钟内。大讨论男孩,谢谢! – 2009-02-27 17:43:38