visa nek

visa nek

  • NA
  • 1
  • 1.7k

Converting Assembly, its Classes and its properties to an XML file after assigning the values to all properties using Reflection

Nov 8 2012 8:35 AM

Hi,

I have an assembly, its classes, and its properties and I need to assign the values to those properties and convert that object to XML using Reflection.

Below are the steps, which i have followed:

1.  Load assembly to assembly object

2.  Load its classes to class<type> object.

3.  Create an object of Dictionary<string, object>

4.  Loop each class.

5.  In each loop,

     1.  Create an instace of class using dictionary, get its types and its properties.

     2.  On the other hand, get the data of all properties into the datatable.

     3.  Create array instance and its lenght based on the rows of datatable.

     4.  Loop through all properties. again, take another object propobj= myassembly.createinstance(cls.fullname). If it is a property, i am setting the value to the propobj.  It if a subclass, I am ignoring (bcz this will come again in my class loop.  Then, i assign the values to the subclass).  Once all the properties are set with the values, then add this object values to an array like arrayobj.setvalue(propobj, i).

     5.  Finally, add this array to the dictionary by providing the property name like - objDict[cls.name].GetType().GetProperty("ClassName").Setvalue(objDict[cls.name], arrayobj, null);

6.  Now, I Serialize the final dictionary into an XML.

The issue here is - in my 5th point, I need to set the arrayobj values to my parent class by passing its subclass name as a property.  Here, I am not able to find the parent class name.


My Class Names look like this: 

1.  Class1

2.  Class1SubClass1

3.  Class1Subclass1SubSubClass1

4.  Class1Subclass1SubSubClass2

5.  Class1SubClass2, etc.....


Can anyone please give me the solution for this.

Since this is an urgent requirement, immediate response is highly appreciated.

Thanq