Example #1
0
            public override void ReadObject(ref object result, Utils.Xml.XmlDocElement xmlElement, Type expectedType)
            {
                if (result == null)
                {
                    throw new Exception("Cannot load an unknown type of dictionary");
                }

                Type keyType   = null;
                Type valueType = null;

                if ((expectedType != null) && (expectedType.IsGenericType))
                {
                    keyType   = GenericArgumentLookup(expectedType, 0);
                    valueType = GenericArgumentLookup(expectedType, 1);
                }

                IDictionary dictionary = result as IDictionary;

                foreach (Xml.XmlDocElement itemElement in xmlElement.GetChildElements("Item"))
                {
                    Xml.XmlDocElement keyElement   = itemElement["Key"];
                    Xml.XmlDocElement valueElement = itemElement["Value"];
                    if (keyElement.Exists && valueElement.Exists)
                    {
                        object key = null;
                        DefaultSerializer.ReadObject(ref key, keyElement, keyType);
                        object value = null;
                        DefaultSerializer.ReadObject(ref value, valueElement, valueType);

                        dictionary.Add(key, value);
                    }
                }
            }
Example #2
0
            public override void ReadObject(ref object result, Utils.Xml.XmlDocElement xmlElement, Type expectedType)
            {
                if (result == null)
                {
                    throw new Exception("Cannot load an unknown type of list");
                }

                Type itemType = null;

                if ((expectedType != null) && (expectedType.IsGenericType))
                {
                    itemType = GenericArgumentLookup(expectedType, 0);
                }

                var list = result as IList;

                foreach (Xml.XmlDocElement itemElement in xmlElement.GetChildElements("Item"))
                {
                    object child = null;
                    DefaultSerializer.ReadObject(ref child, itemElement, itemType);
                    if (list != null)
                    {
                        list.Add(child);
                    }
                    else
                    {
                        expectedType.InvokeMember("Add", BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, result, new object[] { child });
                    }
                }
            }