Esempio n. 1
0
        private static Dictionary <K, V> DictionaryFromXml <K, V>(XmlNode dictRootNode) where K : new() where V : new()
        {
            Dictionary <K, V> dictionary = new Dictionary <K, V>();

            try
            {
                bool flag  = typeof(Def).IsAssignableFrom(typeof(K));
                bool flag2 = typeof(Def).IsAssignableFrom(typeof(V));
                if (!flag && !flag2)
                {
                    foreach (XmlNode xmlNode in dictRootNode.ChildNodes)
                    {
                        if (DirectXmlToObject.ValidateListNode(xmlNode, dictRootNode, typeof(KeyValuePair <K, V>)))
                        {
                            K key   = DirectXmlToObject.ObjectFromXml <K>(xmlNode["key"], true);
                            V value = DirectXmlToObject.ObjectFromXml <V>(xmlNode["value"], true);
                            dictionary.Add(key, value);
                        }
                    }
                }
                else
                {
                    foreach (XmlNode xmlNode2 in dictRootNode.ChildNodes)
                    {
                        if (DirectXmlToObject.ValidateListNode(xmlNode2, dictRootNode, typeof(KeyValuePair <K, V>)))
                        {
                            DirectXmlCrossRefLoader.RegisterDictionaryWantsCrossRef <K, V>(dictionary, xmlNode2);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Malformed dictionary XML. Node: ",
                    dictRootNode.OuterXml,
                    ".\n\nException: ",
                    ex
                }));
            }
            return(dictionary);
        }
        private static Dictionary <K, V> DictionaryFromXml <K, V>(XmlNode dictRootNode)
        {
            Dictionary <K, V> dictionary = new Dictionary <K, V>();

            try
            {
                bool num  = typeof(Def).IsAssignableFrom(typeof(K));
                bool flag = typeof(Def).IsAssignableFrom(typeof(V));
                if (!num && !flag)
                {
                    foreach (XmlNode childNode in dictRootNode.ChildNodes)
                    {
                        if (ValidateListNode(childNode, dictRootNode, typeof(KeyValuePair <K, V>)))
                        {
                            K key   = ObjectFromXml <K>(childNode["key"], doPostLoad: true);
                            V value = ObjectFromXml <V>(childNode["value"], doPostLoad: true);
                            dictionary.Add(key, value);
                        }
                    }
                    return(dictionary);
                }
                foreach (XmlNode childNode2 in dictRootNode.ChildNodes)
                {
                    if (ValidateListNode(childNode2, dictRootNode, typeof(KeyValuePair <K, V>)))
                    {
                        DirectXmlCrossRefLoader.RegisterDictionaryWantsCrossRef(dictionary, childNode2, dictRootNode.Name);
                    }
                }
                return(dictionary);
            }
            catch (Exception ex)
            {
                Log.Error("Malformed dictionary XML. Node: " + dictRootNode.OuterXml + ".\n\nException: " + ex);
                return(dictionary);
            }
        }
        private static Dictionary <K, V> DictionaryFromXml <K, V>(XmlNode dictRootNode) where K : new() where V : new()
        {
            Dictionary <K, V> dictionary = new Dictionary <K, V>();

            try
            {
                bool flag  = typeof(Def).IsAssignableFrom(typeof(K));
                bool flag2 = typeof(Def).IsAssignableFrom(typeof(V));
                if (!flag && !flag2)
                {
                    IEnumerator enumerator = dictRootNode.ChildNodes.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            object  obj     = enumerator.Current;
                            XmlNode xmlNode = (XmlNode)obj;
                            if (DirectXmlToObject.ValidateListNode(xmlNode, dictRootNode, typeof(KeyValuePair <K, V>)))
                            {
                                K key   = DirectXmlToObject.ObjectFromXml <K>(xmlNode["key"], true);
                                V value = DirectXmlToObject.ObjectFromXml <V>(xmlNode["value"], true);
                                dictionary.Add(key, value);
                            }
                        }
                    }
                    finally
                    {
                        IDisposable disposable;
                        if ((disposable = (enumerator as IDisposable)) != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }
                else
                {
                    IEnumerator enumerator2 = dictRootNode.ChildNodes.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            object  obj2     = enumerator2.Current;
                            XmlNode xmlNode2 = (XmlNode)obj2;
                            if (DirectXmlToObject.ValidateListNode(xmlNode2, dictRootNode, typeof(KeyValuePair <K, V>)))
                            {
                                DirectXmlCrossRefLoader.RegisterDictionaryWantsCrossRef <K, V>(dictionary, xmlNode2, dictRootNode.Name);
                            }
                        }
                    }
                    finally
                    {
                        IDisposable disposable2;
                        if ((disposable2 = (enumerator2 as IDisposable)) != null)
                        {
                            disposable2.Dispose();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Malformed dictionary XML. Node: ",
                    dictRootNode.OuterXml,
                    ".\n\nException: ",
                    ex
                }), false);
            }
            return(dictionary);
        }
Esempio n. 4
0
        private static Dictionary <K, V> DictionaryFromXml <K, V>(XmlNode dictRootNode) where K : new()where V : new()
        {
            Dictionary <K, V> dictionary = new Dictionary <K, V>();

            try
            {
                bool flag  = typeof(Def).IsAssignableFrom(typeof(K));
                bool flag2 = typeof(Def).IsAssignableFrom(typeof(V));
                if (!flag && !flag2)
                {
                    IEnumerator enumerator = dictRootNode.ChildNodes.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            XmlNode xmlNode = (XmlNode)enumerator.Current;
                            if (ValidateListNode(xmlNode, dictRootNode, typeof(KeyValuePair <K, V>)))
                            {
                                K key   = ObjectFromXml <K>(xmlNode["key"], doPostLoad: true);
                                V value = ObjectFromXml <V>(xmlNode["value"], doPostLoad: true);
                                dictionary.Add(key, value);
                            }
                        }
                        return(dictionary);
                    }
                    finally
                    {
                        IDisposable disposable;
                        if ((disposable = (enumerator as IDisposable)) != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }
                IEnumerator enumerator2 = dictRootNode.ChildNodes.GetEnumerator();
                try
                {
                    while (enumerator2.MoveNext())
                    {
                        XmlNode xmlNode2 = (XmlNode)enumerator2.Current;
                        if (ValidateListNode(xmlNode2, dictRootNode, typeof(KeyValuePair <K, V>)))
                        {
                            DirectXmlCrossRefLoader.RegisterDictionaryWantsCrossRef(dictionary, xmlNode2, dictRootNode.Name);
                        }
                    }
                    return(dictionary);
                }
                finally
                {
                    IDisposable disposable2;
                    if ((disposable2 = (enumerator2 as IDisposable)) != null)
                    {
                        disposable2.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Malformed dictionary XML. Node: " + dictRootNode.OuterXml + ".\n\nException: " + ex);
                return(dictionary);
            }
        }