Beispiel #1
0
        private XElement ToXml(object obj, PropertyInfo pInfo)
        {
            if (pInfo == null)
            {
                return(null);
            }
            object[] atts = pInfo.GetCustomAttributes(typeof(XmlPersistAttribute), false);
            if (atts == null || atts.Length == 0)
            {
                return(ValueTypePropertyToXml(obj, pInfo));
            }
            XmlPersistAttribute xlmPersistAtt = atts[0] as XmlPersistAttribute;
            IPropertyConverter  convter       = null;

            try
            {
                convter = Activator.CreateInstance(xlmPersistAtt.PropertyConverter) as IPropertyConverter;
                object propertyValue = obj.GetType().InvokeMember(pInfo.Name, BindingFlags.GetProperty, null, obj, null);
                if (propertyValue != null)
                {
                    return(convter.ToXml(pInfo.Name, propertyValue));
                }
                return(null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Beispiel #2
0
        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 });
        }