Inheritance: IXmlTypeSerialiser
コード例 #1
0
        protected override void WriteValue(XmlWriter writer, object value)
        {
            IDictionary dictionary = (IDictionary)value;

            foreach (object key in dictionary.Keys)
            {
                object target = dictionary[key];

                // any way to refactor code block?
                ReflectorTypeAttribute typeAttribute = ReflectorTypeAttribute.GetAttribute(target);
                if (typeAttribute == null)
                {
                    writer.WriteStartElement(elementName);
                    writer.WriteAttributeString(attribute.Key, key.ToString());
                    writer.WriteString(target.ToString());
                    writer.WriteEndElement();
                }
                else
                {
                    writer.WriteStartElement(typeAttribute.Name);
                    writer.WriteAttributeString(attribute.Key, key.ToString());

                    XmlTypeSerialiser serialiser = (XmlTypeSerialiser)typeAttribute.CreateSerialiser(target.GetType());
                    serialiser.WriteMembers(writer, target);

                    writer.WriteEndElement();
                }
            }
        }
コード例 #2
0
        protected virtual void WriteValue(XmlWriter writer, object value)
        {
            ReflectorTypeAttribute attribute = ReflectorTypeAttribute.GetAttribute(value);

            if (attribute == null)
            {
                writer.WriteString(value.ToString());
            }
            else
            {
                XmlTypeSerialiser serialiser = (XmlTypeSerialiser)attribute.CreateSerialiser(value.GetType());
                serialiser.WriteMembers(writer, value);
            }
        }