Guest User

Untitled

a guest
Jun 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. namespace tmp {
  2. public class myClass
  3. {
  4. public class InnerClass
  5. {
  6. public int I { get; set; }
  7. public int B { get; set; }
  8. }
  9. public string Prop1 { get; set; }
  10. public Test Prop2 { get; set; }
  11. }
  12. }
  13. }
  14.  
  15. Type type = Type.GetType("tmp.myClass");
  16. object objInstance = Activator.CreateInstance(type);
  17. PropertyInfo[] properties = type.GetProperties();
  18. myClass obj = Activator.CreateInstance(type);
  19.  
  20. properties[0].SetValue(obj,"MyString");
  21.  
  22. Type type1 = Type.GetType("tmp.myClass");
  23. Type type2 = Type.GetType("tmp.myClass.InnerClass");
  24. var obj = Activator.CreateInstance(type1);
  25. var obj2 = Activator.CreateInstance(type2);
  26.  
  27. PropertyInfo[] properties = type1.GetProperties();
  28. properties[1].SetValue(obj, obj2);
Add Comment
Please, Sign In to add comment