【发布时间】:2009-09-28 22:20:08
【问题描述】:
我在获取一个属性是另一个类的类的值时遇到问题。
这是一个例子:
public class Person
{
private int age;
private string name;
public Person()
{
Address = new Address();
}
public int Age
{
get { return age; }
set { age = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public Address Address { get; set; }
}
public class Address
{
public string street { get; set; }
public string houseno { get; set; }
}
public class Program
{
static void Main(string[] args)
{
Person person = new Person();
person.Age = 27;
person.Name = "Fernando Vezzali";
person.Address.houseno = "123";
person.Address.street = "albert street";
Type type = typeof(Person);
PropertyInfo[] properties = type.GetProperties();
foreach (PropertyInfo property in properties)
{
Console.WriteLine("{0} = {1}", property.Name, property.GetValue(person, null));
}
}
}
但是有了这个我没有得到地址的值。
有人可以帮忙吗?
【问题讨论】:
标签: reflection c#-2.0