See my Problem:
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
}
}
}
}
I want Create from My Property if its a Class
If you only want to call the parameterless constructor, you can use
Activator.CreateInstancevery simply. If you want to supply arguments or something more complicated, it gets slightly hairier, but it’s still feasible. You haven’t said what you want to do with the instance afterwards though: