Exemplo n.º 1
0
            public override void WriteObject(object o, Utils.Xml.XmlDocElement xmlElement, Type expectedType)
            {
                Type keyType   = null;
                Type valueType = null;

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

                // Make sure the element gets created when there are zero elements in the list
                xmlElement.MakeSureElementExists();
                IDictionary dict = o as System.Collections.IDictionary;

                foreach (DictionaryEntry entry in dict)
                {
                    Xml.XmlDocElement itemElement = xmlElement.AddElement("Item");
                    Xml.XmlDocElement keyElement  = itemElement.AddElement("Key");
                    DefaultSerializer.WriteObject(entry.Key, keyElement, keyType);
                    Xml.XmlDocElement valueElement = itemElement.AddElement("Value");
                    DefaultSerializer.WriteObject(entry.Value, valueElement, valueType);
                }
            }
Exemplo n.º 2
0
            public override void WriteObject(object o, Utils.Xml.XmlDocElement xmlElement, Type expectedType)
            {
                Type itemType = null;

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

                // Make sure the element gets created when there are zero elements in the list
                xmlElement.MakeSureElementExists();
                foreach (object childValue in (o as System.Collections.IEnumerable))
                {
                    Xml.XmlDocElement childElement = xmlElement.AddElement("Item");
                    DefaultSerializer.WriteObject(childValue, childElement, itemType);
                }
            }