本文整理匯總了VB.NET中System.Xml.Serialization.XmlTypeAttribute.XmlTypeAttribute構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET XmlTypeAttribute構造函數的具體用法?VB.NET XmlTypeAttribute怎麽用?VB.NET XmlTypeAttribute使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在類System.Xml.Serialization.XmlTypeAttribute
的用法示例。
在下文中一共展示了XmlTypeAttribute構造函數的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Person
' 導入命名空間
Imports System.IO
Imports System.Xml.Serialization
Public Class Person
Public personName As String
Public address As Address
End Class
Public Class Address
Public state As String
Public zip As String
End Class
Public Class PersonTypeAttribute
Public Shared Sub Main()
Dim myPersonTypeAttribute As New PersonTypeAttribute()
myPersonTypeAttribute.SerializeObject("XmlType.xml")
End Sub
Public Function CreateOverrider() As XmlSerializer
Dim personOverride As New XmlAttributeOverrides()
Dim personAttributes As New XmlAttributes()
Dim personType As New XmlTypeAttribute()
personType.TypeName = "Employee"
personType.Namespace = "http://www.microsoft.com"
personAttributes.XmlType = personType
Dim addressAttributes As New XmlAttributes()
' Create 'XmlTypeAttribute' with 'TypeName' as an argument.
Dim addressType As New XmlTypeAttribute("Address")
addressType.Namespace = "http://www.microsoft.com"
addressAttributes.XmlType = addressType
personOverride.Add(GetType(Person), personAttributes)
personOverride.Add(GetType(Address), addressAttributes)
Dim myXmlSerializer As New XmlSerializer(GetType(Person), personOverride)
Return myXmlSerializer
End Function
Public Sub SerializeObject(filename As String)
Dim myXmlSerializer As XmlSerializer = CreateOverrider()
Dim myAddress As New Address()
myAddress.state = "AAA"
myAddress.zip = "11111"
Dim myPerson As New Person()
myPerson.personName = "Smith"
myPerson.address = myAddress
' Serialize to a file.
Dim writer = New StreamWriter(filename)
myXmlSerializer.Serialize(writer, myPerson)
End Sub
End Class