I have a class with over 100 unique names and over 20 child classes, sometimes in lists. The following is a very simplified illustration of what I mean:
public class classA { public String PropertyA1 { get; set; } public int PropertyA2{get;set;} public List<classB> myList; public classC myClass { get; set; } public void SetProperty(String PropertyName) {
I would like to do two things that may or may not be possible. The first thing I need to do is iterate over all public properties, including child classes and classes in the list, and translate the values. I know that I can do parsing by serializing it in xml and parsing the results. I even have code to convert to xml, since the class function is to create an xml object. However, I'm worried that parsing XML can be much more expensive than accessing properties through reflection. Is it possible to use reflection in this way, and will it be faster than changing xml?
Another thing I would like to do is access to any property that passes the name of the property to the method. I understand that I need a separate method for accessing classes in lists, and may have to convert the list to a dictionary. The question is, will it be possible, and will the code be needed only in the parent class, or will each of the child classes have to repeat the code?
source share