public void ReflectionDemo() { Type productType = typeof(Product); Product p = new Product(); FieldInfo fi = productType.GetField("name",BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); fi.SetValue(p, "set by reflection"); p.ID = 2; p.ShowProduct(); }
public void PropertyDemo() { dynamic dyn = new Product(); //dyn.name = "n1"; error dyn.ID = 1; dyn.ID = dyn.ID + 1; dyn.ShowProduct(); }