How to retrieve member fields from nested classes recursively in C?

In case you are talking about dynamically retrieving fields at runtime, here is a simple recursive example intended for illustration more than utilitiy. Note that by default class fields are inferred to be private.

In case you are talking about dynamically retrieving fields at runtime, here is a simple recursive example intended for illustration more than utilitiy. Note that by default class fields are inferred to be private. Public static void listFields(Type type, bool sameNamespace, int nestLevel = 1) { BindingFlags bf = BindingFlags.

Public | BindingFlags. NonPublic | BindingFlags. Instance; Console.

WriteLine("\r\n{0}Fields of {1}:", tabs(nestLevel - 1), type. Name); foreach (FieldInfo f in type. GetFields(bf)) { Console.

WriteLine("{0}{1} {2} {3}", tabs(nestLevel), (f. IsPublic? "public" : "private"), f.FieldType.Name, f.

Name); Type fieldType = (f.FieldType. IsArray)?F.FieldType.GetElementType() : f. FieldType; if ((type!

= fieldType) && (!sameNamespace || fieldType. Namespace == type. Namespace)) { listFields(fieldType, sameNamespace, nestLevel + 2); } } Console.WriteLine(); } private static String tabs(int count) { return new String(' ', count * 3); } Output of listFields(typeof(Employee), true);: Fields of Employee: private Int32 age private String name private Address address Fields of Address: private Int32 DoorNum private String Street private Int32 Zip private Phone phones Fields of Phone: private String mobile private String homePhone private Dependents dependents Fields of Dependents: private String name private Int32 age private Phone depPhone Fields of Phone: private String mobile private String homePhone If you wanted to actually get the value of a field of an instance, you would use FieldInfo.

GetValue(object).

Finally I got answer for my question: public Employee getEmployee() { var emp=EmployeeProxy.GetEmployee(); return new Employee { name=emp. Name, age=emp. Age, address=emp.AddressType.

Select(a=>new Address{ DoorNum=a. DoorNum, Street=ae. Street, Zip=a.

Zip, }), phones=new Phone{ mobile=PhoneType. Mobile, homePhone=PhoneType. HomePhone, }, dependents=emp.DependentsType.

Select(d=>new Dependents{ name=d. Name, age=d. Age, depPhone=new Phone{ mobile=d.DependentPhone.

Mobile, homePhone=d.DependentPhone. HomePhone, }, }), }; //End of Return } //End of method.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions