Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private bool ReadValueTypeProperty(XElement pElement, object obj)
        {
            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);
            }
            obj.GetType().InvokeMember(proName, BindingFlags.SetProperty, null, obj, new object[] { value });
            return(true);
        }