Ejemplo n.º 1
0
        private static List <T> ListFromXml <T>(XmlNode listRootNode) where T : new()
        {
            List <T> list = new List <T>();

            try
            {
                bool flag = typeof(Def).IsAssignableFrom(typeof(T));
                foreach (XmlNode xmlNode in listRootNode.ChildNodes)
                {
                    if (DirectXmlToObject.ValidateListNode(xmlNode, listRootNode, typeof(T)))
                    {
                        if (flag)
                        {
                            DirectXmlCrossRefLoader.RegisterListWantsCrossRef <T>(list, xmlNode.InnerText);
                        }
                        else
                        {
                            list.Add(DirectXmlToObject.ObjectFromXml <T>(xmlNode, true));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Exception loading list from XML: ",
                    ex,
                    "\nXML:\n",
                    listRootNode.OuterXml
                }));
            }
            return(list);
        }
        private static List <T> ListFromXml <T>(XmlNode listRootNode) where T : new()
        {
            List <T> list = new List <T>();

            try
            {
                bool        flag       = typeof(Def).IsAssignableFrom(typeof(T));
                IEnumerator enumerator = listRootNode.ChildNodes.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object  obj     = enumerator.Current;
                        XmlNode xmlNode = (XmlNode)obj;
                        if (DirectXmlToObject.ValidateListNode(xmlNode, listRootNode, typeof(T)))
                        {
                            if (flag)
                            {
                                DirectXmlCrossRefLoader.RegisterListWantsCrossRef <T>(list, xmlNode.InnerText, listRootNode.Name);
                            }
                            else
                            {
                                list.Add(DirectXmlToObject.ObjectFromXml <T>(xmlNode, true));
                            }
                        }
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Exception loading list from XML: ",
                    ex,
                    "\nXML:\n",
                    listRootNode.OuterXml
                }), false);
            }
            return(list);
        }
Ejemplo n.º 3
0
        private static List <T> ListFromXml <T>(XmlNode listRootNode) where T : new()
        {
            List <T> list = new List <T>();

            try
            {
                bool        flag       = typeof(Def).IsAssignableFrom(typeof(T));
                IEnumerator enumerator = listRootNode.ChildNodes.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        XmlNode xmlNode = (XmlNode)enumerator.Current;
                        if (ValidateListNode(xmlNode, listRootNode, typeof(T)))
                        {
                            if (flag)
                            {
                                DirectXmlCrossRefLoader.RegisterListWantsCrossRef(list, xmlNode.InnerText, listRootNode.Name);
                            }
                            else
                            {
                                list.Add(ObjectFromXml <T>(xmlNode, doPostLoad: true));
                            }
                        }
                    }
                    return(list);
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception loading list from XML: " + ex + "\nXML:\n" + listRootNode.OuterXml);
                return(list);
            }
        }
Ejemplo n.º 4
0
        private static List <T> ListFromXml <T>(XmlNode listRootNode)
        {
            List <T> list = new List <T>();

            try
            {
                bool flag = typeof(Def).IsAssignableFrom(typeof(T));
                foreach (XmlNode childNode in listRootNode.ChildNodes)
                {
                    if (ValidateListNode(childNode, listRootNode, typeof(T)))
                    {
                        XmlAttribute xmlAttribute = childNode.Attributes["MayRequire"];
                        if (flag)
                        {
                            DirectXmlCrossRefLoader.RegisterListWantsCrossRef(list, childNode.InnerText, listRootNode.Name, xmlAttribute?.Value);
                        }
                        else
                        {
                            try
                            {
                                if (xmlAttribute == null || xmlAttribute.Value.NullOrEmpty() || ModsConfig.IsActive(xmlAttribute.Value))
                                {
                                    list.Add(ObjectFromXml <T>(childNode, doPostLoad: true));
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Error("Exception loading list element from XML: " + ex + "\nXML:\n" + listRootNode.OuterXml);
                            }
                        }
                    }
                }
                return(list);
            }
            catch (Exception ex2)
            {
                Log.Error("Exception loading list from XML: " + ex2 + "\nXML:\n" + listRootNode.OuterXml);
                return(list);
            }
        }