Hi
I got a question on how to get the property values using reflection in c#. (It's my first time to use, i think i lost somewhere...)
I have compile an assembly and successfully deserialize a XML to it.
By using 'InvokeMember' method, 'result' can hold the property of 'Deserializeobj ' (image enclosed : ref_Image1.jpg) . Then, i would like to ask how to further get all the values from the collection in 'result'?
Thank you very much
I got a question on how to get the property values using reflection in c#. (It's my first time to use, i think i lost somewhere...)
I have compile an assembly and successfully deserialize a XML to it.
By using 'InvokeMember' method, 'result' can hold the property of 'Deserializeobj ' (image enclosed : ref_Image1.jpg) . Then, i would like to ask how to further get all the values from the collection in 'result'?
Thank you very much
Code:
Type[] ts = assembly.GetTypes(); foreach (Type t in ts) { //Create the object for deserialization object DeserializeObj = t.InvokeMember(t.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, new object[] { }); //Read XML to stream reader StreamReader sr = new StreamReader(txtXMLPath.Text); //Deserialization DeserializeObj = new XmlSerializer(t).Deserialize(sr); //Get the properties of the object PropertyInfo[] pis = DeserializeObj.GetType().GetProperties(); object result = new object(); object result2 = new object(); foreach (PropertyInfo pi in pis) { // Get property in the object result = DeserializeObj.GetType().InvokeMember(pi.Name, BindingFlags.GetProperty, null, DeserializeObj, new object[] { }); result2 = result.GetType().InvokeMember(result.GetType().FullName, BindingFlags.ExactBinding, null, DeserializeObj, new object[] { 0 }); } }
Comment