public void loadParameterFromXML(string xmlFile) { xdoc = XDocument.Load(xmlFile); if (xdoc == null) { throw (new Exception("Unable to load XML file: " + xmlFile)); } var nodes = xdoc.Descendants("Settings"); foreach (XElement n in nodes) { string profileName = n.Attribute("name").Value; F28LightCtrl.F28_PARAMETERS tParams = new F28LightCtrl.F28_PARAMETERS(); var paramNode = n.Descendants("Parameter"); object tP = tParams; foreach (XElement el in paramNode) { string probName = el.Attribute("property_name").Value; string typeStr = el.Attribute("type").Value; string strVal = el.Attribute("value").Value; var field = tParams.GetType().GetField(probName); if (typeStr == "ushort") { ushort uValue = ushort.Parse(strVal); field.SetValue(tP, uValue); } else { float fValue = float.Parse(strVal); field.SetValue(tP, fValue); } } tParams = (F28LightCtrl.F28_PARAMETERS)tP; _controller.addParamToTable(profileName, tParams); } }