private void ReadComplexProperty(XElement pElement, IContourLayer lyr) { string proName = pElement.Name.LocalName; PropertyInfo pInfo = lyr.GetType().GetProperty(proName); object[] atts = pInfo.GetCustomAttributes(typeof(XmlPersistAttribute), false); XmlPersistAttribute xmlPersisitAtt = atts[0] as XmlPersistAttribute; IPropertyConverter convter = Activator.CreateInstance(xmlPersisitAtt.PropertyConverter) as IPropertyConverter; object value = convter.FromXml(pElement); lyr.GetType().InvokeMember(proName, BindingFlags.SetProperty, null, lyr, new object[] { value }); }
private bool ReadValueTypeProperty(XElement pElement, IContourLayer lyr) { string proName = pElement.Name.LocalName; string type = PropertyConverter.AttToString(pElement, "type"); object value = null; if (type == typeof(bool).ToString()) { value = PropertyConverter.AttToBool(pElement, "value"); } else if (type == typeof(int).ToString()) { value = PropertyConverter.AttToInt(pElement, "value"); } else if (type == typeof(string).ToString()) { value = PropertyConverter.AttToString(pElement, "value"); } else if (type == typeof(float).ToString()) { value = PropertyConverter.AttToFloat(pElement, "value"); } else if (type == typeof(byte).ToString()) { value = PropertyConverter.AttToByte(pElement, "value"); } else if (type == typeof(double).ToString()) { value = PropertyConverter.AttToDouble(pElement, "value"); } else { return(false); } lyr.GetType().InvokeMember(proName, BindingFlags.SetProperty, null, lyr, new object[] { value }); return(true); }
public XElement ToXml(IContourLayer contourLayer) { if (contourLayer == null) { return(null); } PropertyInfo[] proInfos = contourLayer.GetType().GetProperties(); if (proInfos == null || proInfos.Length == 0) { return(null); } XElement rootElement = new XElement("ContourLayer"); rootElement.SetAttributeValue("layername", contourLayer.Name ?? string.Empty); foreach (PropertyInfo pInfo in proInfos) { XElement pEle = ToXml(contourLayer, pInfo); if (pEle != null) { rootElement.Add(pEle); } } return(rootElement); }