System.Xml.Serialization.TempAssembly.InvokeWriter C# (CSharp) Method

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
        internal void InvokeWriter(XmlMapping mapping, XmlWriter xmlWriter, object o, XmlSerializerNamespaces namespaces, string encodingStyle, string id) {
            XmlSerializationWriter writer = null;
            try {
                encodingStyle = ValidateEncodingStyle(encodingStyle, mapping.Key);
                writer = Contract.Writer;
                writer.Init(xmlWriter, namespaces, encodingStyle, id, this);
                if (methods[mapping.Key].writeMethod == null) {
                    if (writerMethods == null) {
                        writerMethods = Contract.WriteMethods;
                    }
                    string methodName = (string)writerMethods[mapping.Key];
                    if (methodName == null) {
                        throw new InvalidOperationException(Res.GetString(Res.XmlNotSerializable, mapping.Accessor.Name));
                    }
                    methods[mapping.Key].writeMethod = GetMethodFromType(writer.GetType(), methodName, pregeneratedAssmbly ? assembly : null);
                }
                methods[mapping.Key].writeMethod.Invoke(writer, new object[] { o });
            }
            catch (SecurityException e) {
                throw new InvalidOperationException(Res.GetString(Res.XmlNoPartialTrust), e);
            }
            finally {
                if (writer != null)
                    writer.Dispose();
            }
        }

Usage Example

Example #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();
 }
All Usage Examples Of System.Xml.Serialization.TempAssembly::InvokeWriter