Пример #1
0
        private static object XmlToObject(XElement element, Type type)
        {
            Type dataContractType = GetDataContractType(type);

            if (dataContractType == null)
            {
                throw new A.Commons.Exception.SerializationException("Only DataContract object can be deserialized.");
            }
            object targetObject = Activator.CreateInstance(dataContractType);
            object des          = Activator.CreateInstance(type);
            IEnumerable <XElement> enumerable = element.Elements("property");

            foreach (XElement element2 in enumerable)
            {
                ParseProperty(element2, targetObject);
            }
            CloneUtils.CloneObject(targetObject, des, new string[0]);
            return(des);
        }
Пример #2
0
        private static void Parse(XElement root, ref object targetObject)
        {
            XElement element = root.Element("list");

            if (element != null)
            {
                IList list = XmlToList(element, targetObject.GetType());
                foreach (object obj2 in list)
                {
                    ((IList)targetObject).Add(obj2);
                }
            }
            else
            {
                XElement element2 = root.Element("array");
                if (element2 != null)
                {
                    Array array = XmlToArray(element2, targetObject.GetType());
                    targetObject = array;
                }
                else
                {
                    Type dataContractType = GetDataContractType(targetObject.GetType());
                    if (dataContractType == null)
                    {
                        throw new A.Commons.Exception.SerializationException("Only DataContract object can be deserialized.");
                    }
                    object obj3 = Activator.CreateInstance(dataContractType);
                    IEnumerable <XElement> enumerable = root.Element("object").Elements("property");
                    foreach (XElement element4 in enumerable)
                    {
                        ParseProperty(element4, obj3);
                    }
                    CloneUtils.CloneObject(obj3, targetObject, new string[0]);
                }
            }
        }