本文整理汇总了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