本文整理匯總了VB.NET中System.Xml.Serialization.XmlArrayItemAttribute.XmlArrayItemAttribute構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET XmlArrayItemAttribute構造函數的具體用法?VB.NET XmlArrayItemAttribute怎麽用?VB.NET XmlArrayItemAttribute使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在類System.Xml.Serialization.XmlArrayItemAttribute
的用法示例。
在下文中一共展示了XmlArrayItemAttribute構造函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Main
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Public Class Vehicle
Public id As String
End Class
Public Class Car
Inherits Vehicle
Public Maker As String
End Class
Public Class Transportation
<XmlArrayItem(), _
XmlArrayItem(GetType(Car), ElementName := "Automobile")> _
Public MyVehicles() As Vehicle
End Class
Public Class Run
Public Shared Sub Main()
Dim test As New Run()
test.SerializeObject("XmlArrayItem1.xml")
test.DeserializeObject("XmlArrayItem1.xml")
End Sub
Private Sub SerializeObject(ByVal filename As String)
' Creates an XmlSerializer for the Transportation class.
Dim MySerializer As New XmlSerializer(GetType(Transportation))
' Writing the XML file to disk requires a TextWriter.
Dim myTextWriter As New StreamWriter(filename)
' Creates the object to serialize.
Dim myTransportation As New Transportation()
' Creates objects to add to the array.
Dim myVehicle As New Vehicle()
myVehicle.id = "A12345"
Dim myCar As New Car()
myCar.id = "Car 34"
myCar.Maker = "FamousCarMaker"
myTransportation.MyVehicles = New Vehicle() {myVehicle, myCar}
' Serializes the object, and closes the StreamWriter.
MySerializer.Serialize(myTextWriter, myTransportation)
myTextWriter.Close()
End Sub
Private Sub DeserializeObject(ByVal filename As String)
' Create an XmlSerializer instance.
Dim mySerializer As New XmlSerializer(GetType(Transportation))
Dim myFileStream As New FileStream(filename, FileMode.Open)
Dim myTransportation As Transportation = _
CType(mySerializer.Deserialize(myFileStream), Transportation)
Dim i As Integer
For i = 0 To myTransportation.MyVehicles.Length - 1
Console.WriteLine(myTransportation.MyVehicles(i).id)
Next i
End Sub
End Class
示例2: Main
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Public Class Vehicle
Public id As String
End Class
Public Class Car
Inherits Vehicle
Public Maker As String
End Class
Public Class Transportation
<XmlArrayItem(ElementName := "Transportation"), _
XmlArrayItem(GetType(Car), ElementName := "Automobile")> _
Public MyVehicles() As Vehicle
End Class
Public Class Run
Public Shared Sub Main()
Dim test As New Run()
test.SerializeObject("XmlArrayItem2.xml")
test.DeserializeObject("XmlArrayItem2.xml")
End Sub
Private Sub SerializeObject(ByVal filename As String)
' Creates an XmlSerializer for the Transportation class.
Dim MySerializer As New XmlSerializer(GetType(Transportation))
' Writing the XML file to disk requires a TextWriter.
Dim myTextWriter As New StreamWriter(filename)
Dim myTransportation As New Transportation()
Dim myVehicle As New Vehicle()
myVehicle.id = "A12345"
Dim myCar As New Car()
myCar.id = "Car 34"
myCar.Maker = "FamousCarMaker"
Dim myVehicles() As Vehicle = {myVehicle, myCar}
myTransportation.MyVehicles = myVehicles
' Serializes the object, and closes the StreamWriter.
MySerializer.Serialize(myTextWriter, myTransportation)
myTextWriter.Close()
End Sub
Private Sub DeserializeObject(ByVal filename As String)
' Create the serializer with the type to deserialize.
Dim mySerializer As New XmlSerializer(GetType(Transportation))
Dim myFileStream As New FileStream(filename, FileMode.Open)
Dim myTransportation As Transportation = _
CType(mySerializer.Deserialize(myFileStream), Transportation)
Dim i As Integer
For i = 0 To myTransportation.MyVehicles.Length - 1
Console.WriteLine(myTransportation.MyVehicles(i).id)
Next i
End Sub
End Class
示例3: Main
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Public Class Vehicle
Public id As String
End Class
Public Class Car
Inherits Vehicle
Public Maker As String
End Class
Public Class Transportation
<XmlArrayItem(GetType(Vehicle)), _
XmlArrayItem(GetType(Car))> _
Public MyVehicles() As Vehicle
End Class
Public Class Run
Public Shared Sub Main()
Dim test As New Run()
test.SerializeObject("XmlArrayItem3.xml")
test.DeserializeObject("XmlArrayItem3.xml")
End Sub
Private Sub SerializeObject(ByVal filename As String)
' Creates an XmlSerializer object.
Dim MySerializer As New XmlSerializer(GetType(Transportation))
' Writing the XML file to disk requires a TextWriter.
Dim myTextWriter As New StreamWriter(filename)
Dim myTransportation As New Transportation()
Dim myVehicle As New Vehicle()
myVehicle.id = "A12345"
Dim myCar As New Car()
myCar.id = "Car 34"
myCar.Maker = "FamousCarMaker"
Dim myVehicles() As Vehicle = {myVehicle, myCar}
myTransportation.MyVehicles = myVehicles
' Serializes the object, and closes the StreamWriter.
MySerializer.Serialize(myTextWriter, myTransportation)
myTextWriter.Close()
End Sub
Private Sub DeserializeObject(ByVal filename As String)
' Creates the serializer with the type to deserialize.
Dim mySerializer As New XmlSerializer(GetType(Transportation))
Dim myFileStream As New FileStream(filename, FileMode.Open)
Dim myTransportation As Transportation = _
CType(mySerializer.Deserialize(myFileStream), Transportation)
Dim i As Integer
For i = 0 To myTransportation.MyVehicles.Length - 1
Console.WriteLine(myTransportation.MyVehicles(i).id)
Next i
End Sub
End Class
示例4: Main
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Public Class Vehicle
Public id As String
End Class
Public Class Car
Inherits Vehicle
Public Maker As String
End Class
Public Class Transportation
<XmlArray(), _
XmlArrayItem("Transport", GetType(Vehicle)), _
XmlArrayItem("Automobile", GetType(Car))> _
Public MyVehicles() As Vehicle
End Class
Public Class Run
Public Shared Sub Main()
Dim test As New Run()
test.SerializeObject("XmlArrayItem4.xml")
test.DeserializeObject("XmlArrayItem4.xml")
End Sub
Private Sub SerializeObject(ByVal filename As String)
' Creates an XmlSerializer for the Transportation class.
Dim MySerializer As New XmlSerializer(GetType(Transportation))
' Writing the XML file to disk requires a TextWriter.
Dim myTextWriter As New StreamWriter(filename)
Dim myTransportation As New Transportation()
Dim myVehicle As New Vehicle()
myVehicle.id = "A12345"
Dim myCar As New Car()
myCar.id = "Car 34"
myCar.Maker = "FamousCarMaker"
Dim myVehicles() As Vehicle = {myVehicle, myCar}
myTransportation.MyVehicles = myVehicles
' Serializes the object, and closes the StreamWriter.
MySerializer.Serialize(myTextWriter, myTransportation)
myTextWriter.Close()
End Sub
Private Sub DeserializeObject(ByVal filename As String)
' Creates an XmlSerializer.
Dim mySerializer As New XmlSerializer(GetType(Transportation))
Dim myFileStream As New FileStream(filename, FileMode.Open)
Dim myTransportation As Transportation = _
CType(mySerializer.Deserialize(myFileStream), Transportation)
Dim i As Integer
For i = 0 To myTransportation.MyVehicles.Length - 1
Console.WriteLine(myTransportation.MyVehicles(i).id)
Next i
End Sub
End Class