见我的问题:如何从属性创建实例这是一个类?
public class Address
{
public string Title{get;set;}
public string Description{get;set;}
}
public class Tell
{
public string Title{get;set;}
public string Number{get;set;}
}
public class Person
{
public string FirstName{get;set;}
public string LastName{get;set;}
public Address PAddress {get;set;}
public Tell PTell {get;set;}
void CreateInstanceFromProperties()
{
foreach(var prop in this.GetType().GetProperties())
{
if(prop.PropertyType.IsClass)
{
//Create Instance from this property
}
}
}
}
我想从我的房屋创建如果一个类
首先,请用真实的代码 - C#是区分大小写;你不能使用“Class”和“Public”,你的意思是“foreach”而不是“freeach”等。其次,你想如何创建一个实例 - 只需调用无参数构造函数? – 2012-02-25 11:30:46
@Jon Skeet我编辑我的问题... – 2012-02-25 11:33:45