I was hoping someone would tell me which is a more efficient and / or correct way to get some data.
I have some XML files coming from a third party and their attached DTDs. So I converted the DTD to a C # class so that I could deserialize XML into classes. Now I need to map this data according to the settings of my data structures.
The question is ultimately; should use reflection or LINQ. The XML format is somewhat generalized in design, where things are stored in Items [Array] or Item [Object].
I have done the following:
TheirClass class = theirMessage.Items.Where(n=> n.GetType() == typeof(TheirClass)).First() as TheirClass; MyObject.Param1 = ConversionHelperClass.Convert(class.Obj1); MyObject.Param2 = ConversionHelperClass.Convert(class.Obj2);
I can also do some things with Reflection, where I pass the names of the classes and attributes that I'm trying to hook.
Trying to do it right here.
source share