XmlSerializer Kelas

Definisi

Menserialisasikan dan mendeserialisasi objek ke dalam dan dari dokumen XML. memungkinkan XmlSerializer Anda mengontrol bagaimana objek dikodekan ke dalam XML.

public ref class XmlSerializer
public class XmlSerializer
type XmlSerializer = class
Public Class XmlSerializer
Warisan
XmlSerializer

Contoh

Contoh berikut berisi dua kelas utama: PurchaseOrder dan Test. Kelas PurchaseOrder berisi informasi tentang satu pembelian. Kelas Test berisi metode yang membuat pesanan pembelian, dan yang membaca pesanan pembelian yang dibuat.

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Xml::Serialization;
using namespace System::IO;
ref class Address;
ref class OrderedItem;

/* The XmlRootAttribute allows you to set an alternate name 
   (PurchaseOrder) of the XML element, the element namespace; by 
   default, the XmlSerializer uses the class name. The attribute 
   also allows you to set the XML namespace for the element.  Lastly,
   the attribute sets the IsNullable property, which specifies whether 
   the xsi:null attribute appears if the class instance is set to 
   a null reference. */

[XmlRootAttribute("PurchaseOrder",Namespace="http://www.cpandl.com",
IsNullable=false)]
public ref class PurchaseOrder
{
public:
   Address^ ShipTo;
   String^ OrderDate;

   /* The XmlArrayAttribute changes the XML element name
       from the default of "OrderedItems" to "Items". */

   [XmlArrayAttribute("Items")]
   array<OrderedItem^>^OrderedItems;
   Decimal SubTotal;
   Decimal ShipCost;
   Decimal TotalCost;
};

public ref class Address
{
public:

   /* The XmlAttribute instructs the XmlSerializer to serialize the Name
         field as an XML attribute instead of an XML element (the default
         behavior). */

   [XmlAttributeAttribute]
   String^ Name;
   String^ Line1;

   /* Setting the IsNullable property to false instructs the 
         XmlSerializer that the XML attribute will not appear if 
         the City field is set to a null reference. */

   [XmlElementAttribute(IsNullable=false)]
   String^ City;
   String^ State;
   String^ Zip;
};

public ref class OrderedItem
{
public:
   String^ ItemName;
   String^ Description;
   Decimal UnitPrice;
   int Quantity;
   Decimal LineTotal;

   /* Calculate is a custom method that calculates the price per item,
         and stores the value in a field. */
   void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }

};

public ref class Test
{
public:
   static void main()
   {
      // Read and write purchase orders.
      Test^ t = gcnew Test;
      t->CreatePO( "po.xml" );
      t->ReadPO( "po.xml" );
   }

private:
   void CreatePO( String^ filename )
   {
      // Create an instance of the XmlSerializer class;
      // specify the type of object to serialize.
      XmlSerializer^ serializer = gcnew XmlSerializer( PurchaseOrder::typeid );
      TextWriter^ writer = gcnew StreamWriter( filename );
      PurchaseOrder^ po = gcnew PurchaseOrder;

      // Create an address to ship and bill to.
      Address^ billAddress = gcnew Address;
      billAddress->Name = "Teresa Atkinson";
      billAddress->Line1 = "1 Main St.";
      billAddress->City = "AnyTown";
      billAddress->State = "WA";
      billAddress->Zip = "00000";

      // Set ShipTo and BillTo to the same addressee.
      po->ShipTo = billAddress;
      po->OrderDate = System::DateTime::Now.ToLongDateString();

      // Create an OrderedItem object.
      OrderedItem^ i1 = gcnew OrderedItem;
      i1->ItemName = "Widget S";
      i1->Description = "Small widget";
      i1->UnitPrice = (Decimal)5.23;
      i1->Quantity = 3;
      i1->Calculate();

      // Insert the item into the array.
      array<OrderedItem^>^items = {i1};
      po->OrderedItems = items;

      // Calculate the total cost.
      Decimal subTotal = Decimal(0);
      System::Collections::IEnumerator^ myEnum = items->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         OrderedItem^ oi = safe_cast<OrderedItem^>(myEnum->Current);
         subTotal = subTotal + oi->LineTotal;
      }

      po->SubTotal = subTotal;
      po->ShipCost = (Decimal)12.51;
      po->TotalCost = po->SubTotal + po->ShipCost;

      // Serialize the purchase order, and close the TextWriter.
      serializer->Serialize( writer, po );
      writer->Close();
   }

protected:
   void ReadPO( String^ filename )
   {
      // Create an instance of the XmlSerializer class;
      // specify the type of object to be deserialized.
      XmlSerializer^ serializer = gcnew XmlSerializer( PurchaseOrder::typeid );

      /* If the XML document has been altered with unknown 
            nodes or attributes, handle them with the 
            UnknownNode and UnknownAttribute events.*/
      serializer->UnknownNode += gcnew XmlNodeEventHandler( this, &Test::serializer_UnknownNode );
      serializer->UnknownAttribute += gcnew XmlAttributeEventHandler( this, &Test::serializer_UnknownAttribute );

      // A FileStream is needed to read the XML document.
      FileStream^ fs = gcnew FileStream( filename,FileMode::Open );

      // Declare an object variable of the type to be deserialized.
      PurchaseOrder^ po;

      /* Use the Deserialize method to restore the object's state with
            data from the XML document. */
      po = dynamic_cast<PurchaseOrder^>(serializer->Deserialize( fs ));

      // Read the order date.
      Console::WriteLine( "OrderDate: {0}", po->OrderDate );

      // Read the shipping address.
      Address^ shipTo = po->ShipTo;
      ReadAddress( shipTo, "Ship To:" );

      // Read the list of ordered items.
      array<OrderedItem^>^items = po->OrderedItems;
      Console::WriteLine( "Items to be shipped:" );
      System::Collections::IEnumerator^ myEnum1 = items->GetEnumerator();
      while ( myEnum1->MoveNext() )
      {
         OrderedItem^ oi = safe_cast<OrderedItem^>(myEnum1->Current);
         Console::WriteLine( "\t{0}\t{1}\t{2}\t{3}\t{4}", oi->ItemName, oi->Description, oi->UnitPrice, oi->Quantity, oi->LineTotal );
      }

      Console::WriteLine( "\t\t\t\t\t Subtotal\t{0}", po->SubTotal );
      Console::WriteLine( "\t\t\t\t\t Shipping\t{0}", po->ShipCost );
      Console::WriteLine( "\t\t\t\t\t Total\t\t{0}", po->TotalCost );
   }

   void ReadAddress( Address^ a, String^ label )
   {
      // Read the fields of the Address object.
      Console::WriteLine( label );
      Console::WriteLine( "\t{0}", a->Name );
      Console::WriteLine( "\t{0}", a->Line1 );
      Console::WriteLine( "\t{0}", a->City );
      Console::WriteLine( "\t{0}", a->State );
      Console::WriteLine( "\t{0}", a->Zip );
      Console::WriteLine();
   }

private:
   void serializer_UnknownNode( Object^ /*sender*/, XmlNodeEventArgs^ e )
   {
      Console::WriteLine( "Unknown Node:{0}\t{1}", e->Name, e->Text );
   }

   void serializer_UnknownAttribute( Object^ /*sender*/, XmlAttributeEventArgs^ e )
   {
      System::Xml::XmlAttribute^ attr = e->Attr;
      Console::WriteLine( "Unknown attribute {0}='{1}'", attr->Name, attr->Value );
   }
};

int main()
{
   Test::main();
}
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

/* The XmlRootAttribute allows you to set an alternate name
   (PurchaseOrder) of the XML element, the element namespace; by
   default, the XmlSerializer uses the class name. The attribute
   also allows you to set the XML namespace for the element.  Lastly,
   the attribute sets the IsNullable property, which specifies whether
   the xsi:null attribute appears if the class instance is set to
   a null reference. */
[XmlRootAttribute("PurchaseOrder", Namespace="http://www.cpandl.com",
IsNullable = false)]
public class PurchaseOrder
{
   public Address ShipTo;
   public string OrderDate;
   /* The XmlArrayAttribute changes the XML element name
    from the default of "OrderedItems" to "Items". */
   [XmlArrayAttribute("Items")]
   public OrderedItem[] OrderedItems;
   public decimal SubTotal;
   public decimal ShipCost;
   public decimal TotalCost;
}

public class Address
{
   /* The XmlAttribute instructs the XmlSerializer to serialize the Name
      field as an XML attribute instead of an XML element (the default
      behavior). */
   [XmlAttribute]
   public string Name;
   public string Line1;

   /* Setting the IsNullable property to false instructs the
      XmlSerializer that the XML attribute will not appear if
      the City field is set to a null reference. */
   [XmlElementAttribute(IsNullable = false)]
   public string City;
   public string State;
   public string Zip;
}

public class OrderedItem
{
   public string ItemName;
   public string Description;
   public decimal UnitPrice;
   public int Quantity;
   public decimal LineTotal;

   /* Calculate is a custom method that calculates the price per item,
      and stores the value in a field. */
   public void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }
}

public class Test
{
   public static void Main()
   {
      // Read and write purchase orders.
      Test t = new Test();
      t.CreatePO("po.xml");
      t.ReadPO("po.xml");
   }

   private void CreatePO(string filename)
   {
      // Create an instance of the XmlSerializer class;
      // specify the type of object to serialize.
      XmlSerializer serializer =
      new XmlSerializer(typeof(PurchaseOrder));
      TextWriter writer = new StreamWriter(filename);
      PurchaseOrder po=new PurchaseOrder();

      // Create an address to ship and bill to.
      Address billAddress = new Address();
      billAddress.Name = "Teresa Atkinson";
      billAddress.Line1 = "1 Main St.";
      billAddress.City = "AnyTown";
      billAddress.State = "WA";
      billAddress.Zip = "00000";
      // Set ShipTo and BillTo to the same addressee.
      po.ShipTo = billAddress;
      po.OrderDate = System.DateTime.Now.ToLongDateString();

      // Create an OrderedItem object.
      OrderedItem i1 = new OrderedItem();
      i1.ItemName = "Widget S";
      i1.Description = "Small widget";
      i1.UnitPrice = (decimal) 5.23;
      i1.Quantity = 3;
      i1.Calculate();

      // Insert the item into the array.
      OrderedItem [] items = {i1};
      po.OrderedItems = items;
      // Calculate the total cost.
      decimal subTotal = new decimal();
      foreach(OrderedItem oi in items)
      {
         subTotal += oi.LineTotal;
      }
      po.SubTotal = subTotal;
      po.ShipCost = (decimal) 12.51;
      po.TotalCost = po.SubTotal + po.ShipCost;
      // Serialize the purchase order, and close the TextWriter.
      serializer.Serialize(writer, po);
      writer.Close();
   }

   protected void ReadPO(string filename)
   {
      // Create an instance of the XmlSerializer class;
      // specify the type of object to be deserialized.
      XmlSerializer serializer = new XmlSerializer(typeof(PurchaseOrder));
      /* If the XML document has been altered with unknown
      nodes or attributes, handle them with the
      UnknownNode and UnknownAttribute events.*/
      serializer.UnknownNode+= new
      XmlNodeEventHandler(serializer_UnknownNode);
      serializer.UnknownAttribute+= new
      XmlAttributeEventHandler(serializer_UnknownAttribute);

      // A FileStream is needed to read the XML document.
      FileStream fs = new FileStream(filename, FileMode.Open);
      // Declare an object variable of the type to be deserialized.
      PurchaseOrder po;
      /* Use the Deserialize method to restore the object's state with
      data from the XML document. */
      po = (PurchaseOrder) serializer.Deserialize(fs);
      // Read the order date.
      Console.WriteLine ("OrderDate: " + po.OrderDate);

      // Read the shipping address.
      Address shipTo = po.ShipTo;
      ReadAddress(shipTo, "Ship To:");
      // Read the list of ordered items.
      OrderedItem [] items = po.OrderedItems;
      Console.WriteLine("Items to be shipped:");
      foreach(OrderedItem oi in items)
      {
         Console.WriteLine("\t"+
         oi.ItemName + "\t" +
         oi.Description + "\t" +
         oi.UnitPrice + "\t" +
         oi.Quantity + "\t" +
         oi.LineTotal);
      }
      // Read the subtotal, shipping cost, and total cost.
      Console.WriteLine("\t\t\t\t\t Subtotal\t" + po.SubTotal);
      Console.WriteLine("\t\t\t\t\t Shipping\t" + po.ShipCost);
      Console.WriteLine("\t\t\t\t\t Total\t\t" + po.TotalCost);
   }

   protected void ReadAddress(Address a, string label)
   {
      // Read the fields of the Address object.
      Console.WriteLine(label);
      Console.WriteLine("\t"+ a.Name );
      Console.WriteLine("\t" + a.Line1);
      Console.WriteLine("\t" + a.City);
      Console.WriteLine("\t" + a.State);
      Console.WriteLine("\t" + a.Zip );
      Console.WriteLine();
   }

   private void serializer_UnknownNode
   (object sender, XmlNodeEventArgs e)
   {
      Console.WriteLine("Unknown Node:" +   e.Name + "\t" + e.Text);
   }

   private void serializer_UnknownAttribute
   (object sender, XmlAttributeEventArgs e)
   {
      System.Xml.XmlAttribute attr = e.Attr;
      Console.WriteLine("Unknown attribute " +
      attr.Name + "='" + attr.Value + "'");
   }
}
Imports System.Xml
Imports System.Xml.Serialization
Imports System.IO

' The XmlRootAttribute allows you to set an alternate name
' (PurchaseOrder) of the XML element, the element namespace; by
' default, the XmlSerializer uses the class name. The attribute
' also allows you to set the XML namespace for the element.  Lastly,
' the attribute sets the IsNullable property, which specifies whether
' the xsi:null attribute appears if the class instance is set to
' a null reference. 
<XmlRootAttribute("PurchaseOrder", _
 Namespace := "http://www.cpandl.com", IsNullable := False)> _
Public Class PurchaseOrder
    
    Public ShipTo As Address
    Public OrderDate As String
    ' The XmlArrayAttribute changes the XML element name
    ' from the default of "OrderedItems" to "Items". 
    <XmlArrayAttribute("Items")> _
    Public OrderedItems() As OrderedItem
    Public SubTotal As Decimal
    Public ShipCost As Decimal
    Public TotalCost As Decimal
End Class


Public Class Address
    ' The XmlAttribute instructs the XmlSerializer to serialize the Name
    ' field as an XML attribute instead of an XML element (the default
    ' behavior). 
    <XmlAttribute()> _
    Public Name As String
    Public Line1 As String
    
    ' Setting the IsNullable property to false instructs the
    ' XmlSerializer that the XML attribute will not appear if
    ' the City field is set to a null reference. 
    <XmlElementAttribute(IsNullable := False)> _
    Public City As String
    Public State As String
    Public Zip As String
End Class


Public Class OrderedItem
    Public ItemName As String
    Public Description As String
    Public UnitPrice As Decimal
    Public Quantity As Integer
    Public LineTotal As Decimal
    
    
    ' Calculate is a custom method that calculates the price per item,
    ' and stores the value in a field. 
    Public Sub Calculate()
        LineTotal = UnitPrice * Quantity
    End Sub
End Class


Public Class Test
    
   Public Shared Sub Main()
      ' Read and write purchase orders.
      Dim t As New Test()
      t.CreatePO("po.xml")
      t.ReadPO("po.xml")
   End Sub
    
   Private Sub CreatePO(filename As String)
      ' Create an instance of the XmlSerializer class;
      ' specify the type of object to serialize.
      Dim serializer As New XmlSerializer(GetType(PurchaseOrder))
      Dim writer As New StreamWriter(filename)
      Dim po As New PurchaseOrder()
        
      ' Create an address to ship and bill to.
      Dim billAddress As New Address()
      billAddress.Name = "Teresa Atkinson"
      billAddress.Line1 = "1 Main St."
      billAddress.City = "AnyTown"
      billAddress.State = "WA"
      billAddress.Zip = "00000"
      ' Set ShipTo and BillTo to the same addressee.
      po.ShipTo = billAddress
      po.OrderDate = System.DateTime.Now.ToLongDateString()
        
      ' Create an OrderedItem object.
      Dim i1 As New OrderedItem()
      i1.ItemName = "Widget S"
      i1.Description = "Small widget"
      i1.UnitPrice = CDec(5.23)
      i1.Quantity = 3
      i1.Calculate()
        
      ' Insert the item into the array.
      Dim items(0) As OrderedItem
      items(0) = i1
      po.OrderedItems = items
      ' Calculate the total cost.
      Dim subTotal As New Decimal()
      Dim oi As OrderedItem
      For Each oi In  items
         subTotal += oi.LineTotal
      Next oi
      po.SubTotal = subTotal
      po.ShipCost = CDec(12.51)
      po.TotalCost = po.SubTotal + po.ShipCost
      ' Serialize the purchase order, and close the TextWriter.
      serializer.Serialize(writer, po)
      writer.Close()
   End Sub
    
   Protected Sub ReadPO(filename As String)
      ' Create an instance of the XmlSerializer class;
      ' specify the type of object to be deserialized.
      Dim serializer As New XmlSerializer(GetType(PurchaseOrder))
      ' If the XML document has been altered with unknown
      ' nodes or attributes, handle them with the
      ' UnknownNode and UnknownAttribute events.
      AddHandler serializer.UnknownNode, AddressOf serializer_UnknownNode
      AddHandler serializer.UnknownAttribute, AddressOf serializer_UnknownAttribute
      
      ' A FileStream is needed to read the XML document.
      Dim fs As New FileStream(filename, FileMode.Open)
      ' Declare an object variable of the type to be deserialized.
      Dim po As PurchaseOrder
      ' Use the Deserialize method to restore the object's state with
      ' data from the XML document. 
      po = CType(serializer.Deserialize(fs), PurchaseOrder)
      ' Read the order date.
      Console.WriteLine(("OrderDate: " & po.OrderDate))
        
      ' Read the shipping address.
      Dim shipTo As Address = po.ShipTo
      ReadAddress(shipTo, "Ship To:")
      ' Read the list of ordered items.
      Dim items As OrderedItem() = po.OrderedItems
      Console.WriteLine("Items to be shipped:")
      Dim oi As OrderedItem
      For Each oi In  items
         Console.WriteLine((ControlChars.Tab & oi.ItemName & ControlChars.Tab & _
         oi.Description & ControlChars.Tab & oi.UnitPrice & ControlChars.Tab & _
         oi.Quantity & ControlChars.Tab & oi.LineTotal))
      Next oi
      ' Read the subtotal, shipping cost, and total cost.
      Console.WriteLine(( New String(ControlChars.Tab, 5) & _
      " Subtotal"  & ControlChars.Tab & po.SubTotal))
      Console.WriteLine(New String(ControlChars.Tab, 5) & _
      " Shipping" & ControlChars.Tab & po.ShipCost )
      Console.WriteLine( New String(ControlChars.Tab, 5) & _
      " Total" &  New String(ControlChars.Tab, 2) & po.TotalCost)
    End Sub
    
    Protected Sub ReadAddress(a As Address, label As String)
      ' Read the fields of the Address object.
      Console.WriteLine(label)
      Console.WriteLine(ControlChars.Tab & a.Name)
      Console.WriteLine(ControlChars.Tab & a.Line1)
      Console.WriteLine(ControlChars.Tab & a.City)
      Console.WriteLine(ControlChars.Tab & a.State)
      Console.WriteLine(ControlChars.Tab & a.Zip)
      Console.WriteLine()
    End Sub
        
    Private Sub serializer_UnknownNode(sender As Object, e As XmlNodeEventArgs)
        Console.WriteLine(("Unknown Node:" & e.Name & ControlChars.Tab & e.Text))
    End Sub
    
    
    Private Sub serializer_UnknownAttribute(sender As Object, e As XmlAttributeEventArgs)
        Dim attr As System.Xml.XmlAttribute = e.Attr
        Console.WriteLine(("Unknown attribute " & attr.Name & "='" & attr.Value & "'"))
    End Sub
End Class

Keterangan

Untuk informasi selengkapnya tentang API ini, lihat Keterangan API Tambahan untuk XmlSerializer.

Konstruktor

XmlSerializer()

Menginisialisasi instans baru kelas XmlSerializer.

XmlSerializer(Type)

Menginisialisasi instans XmlSerializer baru kelas yang dapat menserialisasikan objek dari jenis yang ditentukan ke dalam dokumen XML, dan mendeserialisasi dokumen XML ke dalam objek dari jenis yang ditentukan.

XmlSerializer(Type, String)

Menginisialisasi instans XmlSerializer baru kelas yang dapat menserialisasikan objek dari jenis yang ditentukan ke dalam dokumen XML, dan mendeserialisasi dokumen XML ke dalam objek dari jenis yang ditentukan. Menentukan namespace default untuk semua elemen XML.

XmlSerializer(Type, Type[])

Menginisialisasi instans XmlSerializer baru kelas yang dapat menserialisasikan objek dari jenis yang ditentukan ke dalam dokumen XML, dan mendeserialisasi dokumen XML ke dalam objek dari jenis tertentu. Jika properti atau bidang mengembalikan array, extraTypes parameter menentukan objek yang dapat disisipkan ke dalam array.

XmlSerializer(Type, XmlAttributeOverrides)

Menginisialisasi instans XmlSerializer baru kelas yang dapat menserialisasikan objek dari jenis yang ditentukan ke dalam dokumen XML, dan mendeserialisasi dokumen XML ke dalam objek dari jenis yang ditentukan. Setiap objek yang akan diserialisasikan dapat berisi instans kelas, yang dapat menimpa kelebihan beban ini dengan kelas lain.

XmlSerializer(Type, XmlAttributeOverrides, Type[], XmlRootAttribute, String)

Menginisialisasi instans XmlSerializer baru kelas yang dapat menserialisasikan objek jenis Object ke dalam instans dokumen XML, dan mendeserialisasi instans dokumen XML ke dalam objek jenis Object. Setiap objek yang akan diserialisasikan dapat berisi instans kelas, yang menimpa kelebihan beban ini dengan kelas lain. Kelebihan beban ini juga menentukan namespace default untuk semua elemen XML dan kelas yang akan digunakan sebagai elemen akar XML.

XmlSerializer(Type, XmlAttributeOverrides, Type[], XmlRootAttribute, String, String)

Menginisialisasi instans XmlSerializer baru kelas yang dapat menserialisasikan objek jenis Object ke dalam instans dokumen XML, dan mendeserialisasi instans dokumen XML ke dalam objek jenis Object. Setiap objek yang akan diserialisasikan dapat berisi instans kelas, yang menimpa kelebihan beban ini dengan kelas lain. Kelebihan beban ini juga menentukan namespace default untuk semua elemen XML dan kelas yang akan digunakan sebagai elemen akar XML.

XmlSerializer(Type, XmlAttributeOverrides, Type[], XmlRootAttribute, String, String, Evidence)
Kedaluwarsa.

Menginisialisasi instans XmlSerializer baru kelas yang dapat menserialisasikan objek dari jenis yang ditentukan ke dalam instans dokumen XML, dan mendeserialisasi instans dokumen XML ke dalam objek dari jenis yang ditentukan. Kelebihan beban ini memungkinkan Anda untuk menyediakan jenis lain yang dapat ditemui selama operasi serialisasi atau deserialisasi, serta namespace default untuk semua elemen XML, kelas yang akan digunakan sebagai elemen akar XML, lokasinya, dan kredensial yang diperlukan untuk akses.

XmlSerializer(Type, XmlRootAttribute)

Menginisialisasi instans XmlSerializer baru kelas yang dapat menserialisasikan objek dari jenis yang ditentukan ke dalam dokumen XML, dan mendeserialisasi dokumen XML ke dalam objek dari jenis yang ditentukan. Ini juga menentukan kelas yang akan digunakan sebagai elemen akar XML.

XmlSerializer(XmlTypeMapping)

Menginisialisasi instans XmlSerializer kelas menggunakan objek yang memetakan satu jenis ke jenis lainnya.

Metode

CanDeserialize(XmlReader)

Mendapatkan nilai yang menunjukkan apakah ini XmlSerializer dapat mendeserialisasi dokumen XML tertentu.

CreateReader()

Mengembalikan objek yang digunakan untuk membaca dokumen XML yang akan diserialisasikan.

CreateWriter()

Saat ditimpa di kelas turunan, mengembalikan penulis yang digunakan untuk menserialisasikan objek.

Deserialize(Stream)

Mendeserialisasi dokumen XML yang dimuat oleh yang ditentukan Stream.

Deserialize(TextReader)

Mendeserialisasi dokumen XML yang dimuat oleh yang ditentukan TextReader.

Deserialize(XmlReader)

Mendeserialisasi dokumen XML yang dimuat oleh yang ditentukan XmlReader.

Deserialize(XmlReader, String)

Mendeserialisasi dokumen XML yang dimuat oleh gaya yang ditentukan XmlReader dan pengodean.

Deserialize(XmlReader, String, XmlDeserializationEvents)

Mendeserialisasi objek menggunakan data yang dimuat oleh .XmlReader

Deserialize(XmlReader, XmlDeserializationEvents)

Mendeserialisasi dokumen XML yang dimuat oleh yang ditentukan XmlReader dan memungkinkan penimpaan peristiwa yang terjadi selama deserialisasi.

Deserialize(XmlSerializationReader)

Mendeserialisasi dokumen XML yang dimuat oleh yang ditentukan XmlSerializationReader.

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
FromMappings(XmlMapping[])

Mengembalikan array XmlSerializer objek yang dibuat dari array XmlTypeMapping objek.

FromMappings(XmlMapping[], Evidence)
Kedaluwarsa.

Mengembalikan instans kelas yang XmlSerializer dibuat dari pemetaan satu jenis XML ke jenis XML lainnya.

FromMappings(XmlMapping[], Type)

Mengembalikan instans XmlSerializer kelas dari pemetaan yang ditentukan.

FromTypes(Type[])

Mengembalikan array XmlSerializer objek yang dibuat dari array jenis.

GenerateSerializer(Type[], XmlMapping[])

Mengembalikan rakitan yang berisi serializer buatan kustom yang digunakan untuk menserialisasikan atau mendeserialisasi jenis atau jenis yang ditentukan, menggunakan pemetaan yang ditentukan.

GenerateSerializer(Type[], XmlMapping[], CompilerParameters)

Mengembalikan rakitan yang berisi serializer buatan kustom yang digunakan untuk menserialisasikan atau mendeserialisasi jenis atau jenis yang ditentukan, menggunakan pemetaan dan pengaturan dan opsi pengkompilasi yang ditentukan.

GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
GetXmlSerializerAssemblyName(Type)

Mengembalikan nama rakitan yang berisi satu atau beberapa XmlSerializer versi yang dibuat khusus untuk membuat serialisasi atau deserialisasi jenis yang ditentukan.

GetXmlSerializerAssemblyName(Type, String)

Mengembalikan nama rakitan yang berisi serializer untuk jenis yang ditentukan dalam namespace yang ditentukan.

MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
Serialize(Object, XmlSerializationWriter)

Menserialisasikan dokumen XML yang ditentukan Object dan menulis ke file menggunakan XmlSerializationWriter.

Serialize(Stream, Object)

Menserialisasikan dokumen XML yang ditentukan Object dan menulis ke file menggunakan Stream.

Serialize(Stream, Object, XmlSerializerNamespaces)

Menserialisasikan dokumen XML yang ditentukan Object dan menulis ke file menggunakan yang ditentukan yang mereferensikan Stream namespace yang ditentukan.

Serialize(TextWriter, Object)

Menserialisasikan dokumen XML yang ditentukan Object dan menulis ke file menggunakan TextWriter.

Serialize(TextWriter, Object, XmlSerializerNamespaces)

Menserialisasikan dokumen XML yang ditentukan Object dan menulis ke file menggunakan yang ditentukan dan mereferensikan TextWriter namespace yang ditentukan.

Serialize(XmlWriter, Object)

Menserialisasikan dokumen XML yang ditentukan Object dan menulis ke file menggunakan XmlWriter.

Serialize(XmlWriter, Object, XmlSerializerNamespaces)

Menserialisasikan dokumen XML yang ditentukan Object dan menulis ke file menggunakan yang ditentukan dan mereferensikan XmlWriter namespace yang ditentukan.

Serialize(XmlWriter, Object, XmlSerializerNamespaces, String)

Menserialisasikan objek yang ditentukan dan menulis dokumen XML ke file menggunakan yang ditentukan dan mereferensikan XmlWriter namespace dan gaya pengodean yang ditentukan.

Serialize(XmlWriter, Object, XmlSerializerNamespaces, String, String)

Menserialisasikan dokumen XML yang ditentukan Object dan menulis ke file menggunakan namespace , XML, dan pengodean yang ditentukan XmlWriter.

ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Acara

UnknownAttribute

Terjadi ketika XmlSerializer menemukan atribut XML dari jenis yang tidak diketahui selama deserialisasi.

UnknownElement

Terjadi ketika XmlSerializer menemukan elemen XML dari jenis yang tidak diketahui selama deserialisasi.

UnknownNode

Terjadi ketika XmlSerializer menemukan simpul XML dari jenis yang tidak diketahui selama deserialisasi.

UnreferencedObject

Terjadi selama deserialisasi aliran XML yang dikodekan SOAP, ketika XmlSerializer menemukan jenis yang dikenali yang tidak digunakan atau tidak direferensikan.

Berlaku untuk

Keamanan Thread

Jenis ini aman untuk utas.

Lihat juga