コード例 #1
0
        public object FromXml(XElement element)
        {
            var proElements = element.Elements();

            if (proElements == null)
            {
                return(null);
            }
            string assembly = PropertyConverter.AttToString(element, "assembly");
            string type     = PropertyConverter.AttToString(element, "type");
            object obj      = Activator.CreateInstance(assembly, type);

            if (obj is ObjectHandle)
            {
                obj = (obj as ObjectHandle).Unwrap();
            }
            foreach (XElement pElement in proElements)
            {
                if (ReadValueTypeProperty(pElement, obj))
                {
                    continue;
                }
                ReadComplexProperty(pElement, obj);
            }
            return(obj);
        }
コード例 #2
0
        public IContourLayer FromXml(XElement element)
        {
            var proElements = element.Elements();

            if (proElements == null)
            {
                return(null);
            }
            IContourLayer lyr = new ContourLayer(PropertyConverter.AttToString(element, "layername"));

            foreach (XElement pElement in proElements)
            {
                if (ReadValueTypeProperty(pElement, lyr))
                {
                    continue;
                }
                ReadComplexProperty(pElement, lyr);
            }
            return(lyr);
        }
コード例 #3
0
        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);
        }