我需要访问基类类属性,它是来自已分类类的列表。下面是例子,我需要这个单元测试。从派生类c访问基类(列表)属性#
class child : List<Parent>
{
//this class is empty.
}
class Parent
{
public List<Seller> Seller
{
get;
set;
}
public string Id
{
get;
set;
}
}
我不能够访问父类的任何属性。请帮忙。
单元测试代码
[Test]
public class test()
{
child a = new child();
a. // not showing any properties of parent
}
孩子从'List'继承,而不是'Parent'。所以这是一个“集合”。你必须做一些像'foreach(var parent in a){var id = parent.Id;}' –
2014-09-10 10:15:24
我不会在这种情况下得到parent.id – user3660473 2014-09-10 10:19:37
你是什么意思?如果你不在'List'中添加任何'Parent'(做一些像'a.Add(new Parent {Id = 2})'),当然你不会有任何东西...... –
2014-09-10 10:29:46