예제 #1
0
        /// <summary>
        /// Serializers the provided object using the provided <see cref="writer"/> and <see cref="parameters"/>.
        /// </summary>
        /// <param name="obj">The object to serializer</param>
        /// <param name="writer">The <see cref="XmlWriter"/> to serialize to</param>
        /// <param name="parameters">The parameters used for serialization<m/param>
        public virtual void Serialize(T obj, XmlWriter writer, SerializationParameters parameters)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            var state = new SerializationContext(this.Options, parameters);

            if (!parameters.ContainsByName("ExcludeXmlDecl"))
            {
                writer.WriteStartDocument();
            }

            if (rootMemberInfo.Namespace.Length > 0)
            {
                writer.WriteStartElement(parameters.Namespaces.GetPrefix(rootMemberInfo.Namespace), rootMemberInfo.SerializedName, rootMemberInfo.Namespace);
            }
            else
            {
                writer.WriteStartElement(rootMemberInfo.SerializedName);
            }

            foreach (string prefix in parameters.Namespaces.GetPrefixes())
            {
                writer.WriteAttributeString("xmlns", prefix, null, parameters.Namespaces.GetNamespace(prefix));
            }

            rootMemberInfo.GetSerializer(obj).Serialize(obj, writer, state);

            writer.WriteEndElement();
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="writer"></param>
        /// <param name="parameters"></param>
        public virtual void Serialize(T obj, TextWriter writer, SerializationParameters parameters)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            var textWriter = new XmlTextWriter(writer);

            textWriter.Formatting = this.Formatting;

            Serialize(obj, textWriter, parameters);
        }
예제 #3
0
        /// <summary>
        /// Deserializers an object from the given <see cref="reader"/>
        /// </summary>
        /// <param name="instance">An existing instance to populate</param>
        /// <param name="parameters">The paramters for deserialization</param>
        /// <param name="reader">The reader<see cref="XmlReader"/> to deserialize from</param>
        /// <returns>The deserialized object</returns>
        public virtual T Deserialize(T instance, XmlReader reader, SerializationParameters parameters)
        {
            var state = new SerializationContext(this.Options, parameters);

            reader.Read();

            XmlReaderHelper.ReadUntilTypeReached(reader, XmlNodeType.Element);

            if (reader.NodeType != XmlNodeType.Element)
            {
                throw new XmlSerializerException("Can't find root XML node.");
            }

            var reval = (T)((ComplexTypeTypeSerializer)rootMemberInfo.GetSerializer(reader)).Deserialize(instance, reader, state);

            return(reval);
        }
 public SerializationContext(SerializerOptions options, SerializationParameters parameters)
 {
     this.Parameters = parameters;
     SerializerOptions = options;
 }
예제 #5
0
 public override U Deserialize(string xml, SerializationParameters parameters)
 {
     return((U)(object)serializer.Deserialize(xml, parameters));
 }
예제 #6
0
 public override U Deserialize(TextReader reader, SerializationParameters parameters)
 {
     return((U)(object)serializer.Deserialize(reader, parameters));
 }
예제 #7
0
 public override void Serialize(U obj, TextWriter writer, SerializationParameters parameters)
 {
     serializer.Serialize((T)(object)obj, writer, parameters);
 }
예제 #8
0
 /// <summary>
 /// Deserializes an object from the given xml string.
 /// </summary>
 /// <param name="xml">The xml string to deserialize from</param>
 /// <param name="parameters">The <see cref="SerializationParameters"/> for deserialization</param>
 /// <returns>The deserialized object</returns>
 public virtual T Deserialize(T instance, string xml, SerializationParameters parameters)
 {
     return(Deserialize(instance, new StringReader(xml), parameters));
 }
예제 #9
0
 /// <summary>
 /// Deserializes an object from the given <see cref="TextReader"/>
 /// </summary>
 /// <param name="reader">The <see cref="TextReader"/> to deserialize from</param>
 /// <param name="parameters">The <see cref="SerializationParameters"/> for deserialization</param>
 /// <returns>The deserialized object</returns>
 public virtual T Deserialize(T instance, TextReader reader, SerializationParameters parameters)
 {
     return(Deserialize(instance, new XmlTextReader(reader), parameters));
 }
예제 #10
0
 public SerializationContext(SerializerOptions options, SerializationParameters parameters)
 {
     this.Parameters   = parameters;
     SerializerOptions = options;
 }