See below code and can someone help me….
public class person
{
Public string name { get; set; };
Public personDetails Pdetails { get; };
}
public class personDetails
{
Public bool hasChild { get; set; }
Public string ChildName { get; set; }
}
static void Main(string[] args)
{
Type type = asm.GetType(person);
object classInstance = Activator.CreateInstance(type);
PropertyInfo prop = type.GetProperty("Pdetails ", BindingFlags.Public | BindingFlags.Instance);
if (null != prop && prop.CanWrite)
{
prop.SetValue(classInstance, null , null);
}
}
getting Error for property not found.
The property
Pdetailsis notpublic, so yourBindingFlagsshould beAlso, see Joel Etherton’s answer.