L A

L A

  • NA
  • 170
  • 171.2k

Get all members (Props, fields) of a class, with in a class

May 15 2018 2:00 AM
Hi,
 
I'm looking for an efficient way to get all properties/ fields of complex type which internally have Properties of another complex type.
  1. class A  
  2. {    
  3.     public int Id{get;set;}  
  4.     public string Name{get;set;}  
  5.     public List<string> Branch{get;set;}  
  6.     public BuildData build {get;set;}  
  7.     public SampleData sample {get;set;}  
  8.     public DummyData dData {get;set}  
  9.     //constructor  
  10.     public A(){}  
  11. }  
  12.     
  13. class BuildData{  
  14.     private string _buildData;  
  15.     public string param1{get;set;}  
  16.     public string[] paramArgs{get;set;}  
  17. }  
  18. class SampleData {  
  19.     public string Test{get;set;}  
  20.     public List<DummyData> dummyArgs{get;set;}  
  21. }  
  22.     
  23. class DummyData {  
  24.     public int Val{get;set;}  
  25.     public string GUIData{get;set;}  
  26. }  
I have to use class A & get all its members (fields, Props) which should also include members of other complex types such as DummyData, BuildData, SampleData.
 
I tried using Reflection but couldn't get all members. Followed this article (https://www.c-sharpcorner.com/UploadFile/ff2f08/deep-copy-of-object-in-C-Sharp/) - but couldn't achieve it.

Answers (1)