internal static Dictionary DeserializeXml()

in Darabonba/Utils/XmlUtils.cs [24:65]


        internal static Dictionary<string, object> DeserializeXml(string xmlStr, Type type)
        {
            Dictionary<string, object> result = new Dictionary<string, object>();
            XmlDocument contentXmlDoc = new XmlDocument();
            contentXmlDoc.LoadXml(xmlStr);

            XmlNodeList nodeList = contentXmlDoc.ChildNodes;
            for (int i = 0; i < nodeList.Count; i++)
            {
                XmlNode root = nodeList.Item(i);
                if (type != null)
                {
                    PropertyInfo[] properties = type.GetProperties();
                    foreach (PropertyInfo p in properties)
                    {
                        Type propertyType = p.PropertyType;
                        NameInMapAttribute attribute = p.GetCustomAttribute(typeof(NameInMapAttribute)) as NameInMapAttribute;
                        string realName = attribute == null ? p.Name : attribute.Name;
                        if (root.Name == realName)
                        {
                            if (!typeof(Model).IsAssignableFrom(propertyType))
                            {
                                result.Add(realName, root.InnerText);
                            }
                            else
                            {
                                result.Add(realName, GetDictFromXml(root, propertyType));
                            }
                        }
                    }
                }
                else
                {
                    ElementToDict(root, result);
                }
            }
            if (result.ContainsKey("xml") && result["xml"].ToString().Contains("version=\"1.0\""))
            {
                result.Remove("xml");
            }
            return result;
        }