InvokeWriter() private method

private InvokeWriter ( XmlMapping mapping, XmlWriter xmlWriter, object o, XmlSerializerNamespaces namespaces, string encodingStyle, string id ) : void
mapping XmlMapping
xmlWriter System.Xml.XmlWriter
o object
namespaces XmlSerializerNamespaces
encodingStyle string
id string
return void
Exemplo n.º 1
0
 /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.Serialize6"]/*' />
 // SOAP12: made this internal
 internal void Serialize(XmlWriter xmlWriter, object o, XmlSerializerNamespaces namespaces, string encodingStyle)
 {
     try {
         if (tempAssembly == null)
         {
             XmlSerializationWriter writer = CreateWriter();
             writer.Init(xmlWriter, (namespaces == null || namespaces.Count == 0 ? defaultNamespaces : namespaces).NamespaceList, encodingStyle, null);
             try {
                 Serialize(o, writer);
             }
             finally {
                 writer.Dispose();
             }
         }
         else
         {
             tempAssembly.InvokeWriter(methodIndex, xmlWriter, o, (namespaces == null || namespaces.Count == 0 ? defaultNamespaces : namespaces).NamespaceList, encodingStyle);
         }
     }
     catch (Exception e) {
         if (e is TargetInvocationException)
         {
             e = e.InnerException;
         }
         throw new InvalidOperationException(Res.GetString(Res.XmlGenError), e);
     }
     xmlWriter.Flush();
 }
Exemplo n.º 2
0
        /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.Serialize6"]/*' />
        public void Serialize(XmlWriter xmlWriter, object o, XmlSerializerNamespaces namespaces, string encodingStyle, string id)
        {
            try
            {
                if (_primitiveType != null)
                {
                    if (encodingStyle != null && encodingStyle.Length > 0)
                    {
                        throw new InvalidOperationException(SR.Format(SR.XmlInvalidEncodingNotEncoded1, encodingStyle));
                    }
                    SerializePrimitive(xmlWriter, o, namespaces);
                }
#if !NET_NATIVE
                else if (_tempAssembly == null || _typedSerializer)
                {
                    XmlSerializationWriter writer = CreateWriter();
                    writer.Init(xmlWriter, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id, _tempAssembly);
                    try
                    {
                        Serialize(o, writer);
                    }
                    finally
                    {
                        writer.Dispose();
                    }
                }
                else
                {
                    _tempAssembly.InvokeWriter(_mapping, xmlWriter, o, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id);
                }
#else
                else
                {
                    if (this.innerSerializer == null)
                    {
                        throw new InvalidOperationException(SR.Format(SR.Xml_MissingSerializationCodeException, this.rootType, typeof(XmlSerializer).Name));
                    }

                    if (!string.IsNullOrEmpty(this.DefaultNamespace))
                    {
                        this.innerSerializer.DefaultNamespace = this.DefaultNamespace;
                    }

                    XmlSerializationWriter writer = this.innerSerializer.CreateWriter();
                    writer.Init(xmlWriter, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id);
                    try
                    {
                        this.innerSerializer.Serialize(o, writer);
                    }
                    finally
                    {
                        writer.Dispose();
                    }
                }
#endif
            }
 /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.Serialize6"]/*' />
 public void Serialize(XmlWriter xmlWriter, object o, XmlSerializerNamespaces namespaces, string encodingStyle, string id)
 {
     try {
         if (primitiveType != null)
         {
             if (encodingStyle != null && encodingStyle.Length > 0)
             {
                 throw new InvalidOperationException(Res.GetString(Res.XmlInvalidEncodingNotEncoded1, encodingStyle));
             }
             SerializePrimitive(xmlWriter, o, namespaces);
         }
         else if (tempAssembly == null || typedSerializer)
         {
             XmlSerializationWriter writer = CreateWriter();
             writer.Init(xmlWriter, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id, tempAssembly);
             try {
                 Serialize(o, writer);
             }
             finally {
                 writer.Dispose();
             }
         }
         else
         {
             tempAssembly.InvokeWriter(mapping, xmlWriter, o, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id);
         }
     }
     catch (Exception e) {
         if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
         {
             throw;
         }
         if (e is TargetInvocationException)
         {
             e = e.InnerException;
         }
         throw new InvalidOperationException(Res.GetString(Res.XmlGenError), e);
     }
     catch {
         throw new InvalidOperationException(Res.GetString(Res.XmlGenError), null);
     }
     xmlWriter.Flush();
 }
Exemplo n.º 4
0
        /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.Serialize6"]/*' />
        public void Serialize(XmlWriter xmlWriter, object o, XmlSerializerNamespaces namespaces, string encodingStyle, string id)
        {
            try
            {
                if (_primitiveType != null)
                {
                    if (encodingStyle != null && encodingStyle.Length > 0)
                    {
                        throw new InvalidOperationException(SR.Format(SR.XmlInvalidEncodingNotEncoded1, encodingStyle));
                    }
                    SerializePrimitive(xmlWriter, o, namespaces);
                }
#if !NET_NATIVE
                else if (Mode == SerializationMode.ReflectionOnly)
                {
                    XmlMapping mapping;
                    if (_mapping != null && _mapping.GenerateSerializer)
                    {
                        mapping = _mapping;
                    }
                    else
                    {
                        XmlReflectionImporter importer = new XmlReflectionImporter(DefaultNamespace);
                        mapping = importer.ImportTypeMapping(rootType, null, DefaultNamespace);
                    }

                    var writer = new ReflectionXmlSerializationWriter(mapping, xmlWriter, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id);
                    writer.WriteObject(o);
                }
                else if (_tempAssembly == null || _typedSerializer)
                {
                    // The contion for the block is never true, thus the block is never hit.
                    XmlSerializationWriter writer = CreateWriter();
                    writer.Init(xmlWriter, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id, _tempAssembly);
                    try
                    {
                        Serialize(o, writer);
                    }
                    finally
                    {
                        writer.Dispose();
                    }
                }
                else
                {
                    _tempAssembly.InvokeWriter(_mapping, xmlWriter, o, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id);
                }
#else
                else
                {
                    if (this.innerSerializer != null)
                    {
                        if (!string.IsNullOrEmpty(this.DefaultNamespace))
                        {
                            this.innerSerializer.DefaultNamespace = this.DefaultNamespace;
                        }

                        XmlSerializationWriter writer = this.innerSerializer.CreateWriter();
                        writer.Init(xmlWriter, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id);
                        try
                        {
                            this.innerSerializer.Serialize(o, writer);
                        }
                        finally
                        {
                            writer.Dispose();
                        }
                    }
                    else if (ReflectionMethodEnabled)
                    {
                        XmlMapping mapping;
                        if (_mapping != null && _mapping.GenerateSerializer)
                        {
                            mapping = _mapping;
                        }
                        else
                        {
                            XmlReflectionImporter importer = new XmlReflectionImporter(DefaultNamespace);
                            mapping = importer.ImportTypeMapping(rootType, null, DefaultNamespace);
                        }

                        var writer = new ReflectionXmlSerializationWriter(mapping, xmlWriter, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id);
                        writer.WriteObject(o);
                    }
                    else
                    {
                        throw new InvalidOperationException(SR.Format(SR.Xml_MissingSerializationCodeException, this.rootType, typeof(XmlSerializer).Name));
                    }
                }
#endif
            }
Exemplo n.º 5
0
        public void Serialize(XmlWriter xmlWriter, object o, XmlSerializerNamespaces namespaces, string encodingStyle, string id)
        {
            try
            {
                if (_primitiveType != null)
                {
                    if (encodingStyle != null && encodingStyle.Length > 0)
                    {
                        throw new InvalidOperationException(SR.Format(SR.XmlInvalidEncodingNotEncoded1, encodingStyle));
                    }
                    SerializePrimitive(xmlWriter, o, namespaces);
                }
                else if (ShouldUseReflectionBasedSerialization(_mapping) || _isReflectionBasedSerializer)
                {
                    SerializeUsingReflection(xmlWriter, o, namespaces, encodingStyle, id);
                }
#if !FEATURE_SERIALIZATION_UAPAOT
                else if (_tempAssembly == null || _typedSerializer)
                {
                    // The contion for the block is never true, thus the block is never hit.
                    XmlSerializationWriter writer = CreateWriter();
                    writer.Init(xmlWriter, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id, _tempAssembly);
                    try
                    {
                        Serialize(o, writer);
                    }
                    finally
                    {
                        writer.Dispose();
                    }
                }
                else
                {
                    _tempAssembly.InvokeWriter(_mapping, xmlWriter, o, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id);
                }
#else
                else
                {
                    if (this.innerSerializer != null)
                    {
                        if (!string.IsNullOrEmpty(this.DefaultNamespace))
                        {
                            this.innerSerializer.DefaultNamespace = this.DefaultNamespace;
                        }

                        XmlSerializationWriter writer = this.innerSerializer.CreateWriter();
                        writer.Init(xmlWriter, namespaces == null || namespaces.Count == 0 ? DefaultNamespaces : namespaces, encodingStyle, id);
                        try
                        {
                            this.innerSerializer.Serialize(o, writer);
                        }
                        finally
                        {
                            writer.Dispose();
                        }
                    }
                    else if (ReflectionMethodEnabled)
                    {
                        SerializeUsingReflection(xmlWriter, o, namespaces, encodingStyle, id);
                    }
                    else
                    {
                        throw new InvalidOperationException(SR.Format(SR.Xml_MissingSerializationCodeException, this._rootType, typeof(XmlSerializer).Name));
                    }
                }
#endif
            }