DekGenius.com
[ Team LiB ] Previous Section Next Section

XmlSerializerSystem.Xml.Serialization (system.xml.dll)    class 

public class XmlSerializer {
// Public Constructors
   public XmlSerializer( Type type);  
   public XmlSerializer( Type type, string defaultNamespace);  
   public XmlSerializer( Type type, Type[ ] extraTypes);  
   public XmlSerializer( Type type, XmlAttributeOverrides overrides);  
   public XmlSerializer( Type type, XmlAttributeOverrides overrides, Type[ ] extraTypes, XmlRootAttribute root, string defaultNamespace);  
   public XmlSerializer( Type type, XmlRootAttribute root);  
   public XmlSerializer( XmlTypeMapping xmlTypeMapping);  
// Protected Constructors
   protected XmlSerializer( );  
// Public Static Methods
   public static XmlSerializer[ ] FromMappings( XmlMapping[ ] mappings);  
   public static XmlSerializer[ ] FromTypes( Type[ ] types);  
// Public Instance Methods
   public virtual bool CanDeserialize( System.Xml.XmlReader xmlReader);  
   public object Deserialize( System.IO.Stream stream);  
   public object Deserialize( System.IO.TextReader textReader);  
   public object Deserialize( System.Xml.XmlReader xmlReader);  
   public void Serialize( System.IO.Stream stream, object o);  
   public void Serialize( System.IO.Stream stream, object o, XmlSerializerNamespaces namespaces);  
   public void Serialize( System.IO.TextWriter textWriter, object o);  
   public void Serialize( System.IO.TextWriter textWriter, object o, XmlSerializerNamespaces namespaces);  
   public void Serialize( System.Xml.XmlWriter xmlWriter, object o);  
   public void Serialize( System.Xml.XmlWriter xmlWriter, object o, XmlSerializerNamespaces namespaces);  
// Protected Instance Methods
   protected virtual XmlSerializationReader CreateReader( );  
   protected virtual XmlSerializationWriter CreateWriter( );  
   protected virtual object Deserialize( XmlSerializationReader reader);  
   protected virtual void Serialize( object o, XmlSerializationWriter writer);  
// Events
   public event XmlAttributeEventHandler UnknownAttribute;  
   public event XmlElementEventHandler UnknownElement;  
   public event XmlNodeEventHandler UnknownNode;  
   public event UnreferencedObjectEventHandler UnreferencedObject;  
}

This type provides the core functionality of the System.Xml.Serialization namespace. Various constructors are used to create an instance based on a System.Type or a XmlTypeMapping, and some include parameters to provide extra information on how the object is to be serialized. The staticFromTypes( ) method will create an array of XmlSerializer instances suitable for serializing and deserializing an array of System.Type instances passed in.

The Serialize( ) method does the work of encoding to XML an instance of an object of the type the XmlSerializer is made for. The serialization is performed according to the attributes placed on the object and its members, as well as any XmlAttributeOverrides passed into the constructor. An object can be serialized to any System.IO.Stream, System.IO.TextWriter, or System.Xml.XmlWriter instance.

The staticDeserialize( ) method decodes an object from XML into an instance of the object in memory. The XML object can be deserialized from any System.IO.Stream, System.IO.TextReader, or System.Xml.XmlReader instance that contains XML. Additionally, if using a System.Xml.XmlReader, the CanDeserialize( ) method indicates whether the data in the XML stream is of the proper type to be deserialized by this instance of XmlSerializer.

During deserialization, the XmlSerializer may fire one or more of four events. The UnreferencedObject event is fired if an object deserialized from a SOAP stream has no other object referencing it. If an unknown node is encountered in the XML stream, the UnknownNode event is fired, followed by the UnknownAttribute event if the node is a System.Xml.XmlAttribute, or the UnknownElement event if the node is a System.Xml.XmlElement.

An XmlSerializer instance is created specifically to provide XML serialization for one particular type of object. At the time the XmlSerializer is instantiated, the .NET Framework generates a private assembly to perform the serialization. Because of this, the first time you create a serializer for a particular type, there may be some performance degradation.

    [ Team LiB ] Previous Section Next Section