本文整理汇总了VB.NET中System.Xml.Serialization.XmlAttributeAttribute.XmlAttributeAttribute构造函数的典型用法代码示例。如果您正苦于以下问题:VB.NET XmlAttributeAttribute构造函数的具体用法?VB.NET XmlAttributeAttribute怎么用?VB.NET XmlAttributeAttribute使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。您也可以进一步了解该构造函数所在类System.Xml.Serialization.XmlAttributeAttribute
的用法示例。
在下文中一共展示了XmlAttributeAttribute构造函数的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Student
' 导入命名空间
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
' This is the class that will be serialized.
Public Class Student
Public StudentName As String
Public StudentNumber As Integer
End Class
Public Class Book
Public BookName As String
Public BookNumber As Integer
End Class
Public Class XMLAttributeAttribute_ctr1
Public Shared Sub Main()
Dim myAttribute As New XMLAttributeAttribute_ctr1()
myAttribute.SerializeObject("Student.xml", "Book.xml")
End Sub
Public Sub SerializeObject(studentFilename As String, bookFilename As String)
Dim mySerializer As XmlSerializer
Dim writer As TextWriter
' Create the XmlAttributeOverrides and XmlAttributes objects.
Dim myXmlAttributeOverrides As New XmlAttributeOverrides()
Dim myXmlAttributes As New XmlAttributes()
' Create an XmlAttributeAttribute set it to the XmlAttribute property of the XmlAttributes object.
Dim myXmlAttributeAttribute As New XmlAttributeAttribute()
myXmlAttributeAttribute.AttributeName = "Name"
myXmlAttributes.XmlAttribute = myXmlAttributeAttribute
' Add to the XmlAttributeOverrides. Specify the member name.
myXmlAttributeOverrides.Add(GetType(Student), "StudentName", myXmlAttributes)
' Create the XmlSerializer.
mySerializer = New XmlSerializer(GetType(Student), myXmlAttributeOverrides)
writer = New StreamWriter(studentFilename)
' Create an instance of the class that will be serialized.
Dim myStudent As New Student()
' Set the Name property, which will be generated as an XML attribute.
myStudent.StudentName = "James"
myStudent.StudentNumber = 1
' Serialize the class, and close the TextWriter.
mySerializer.Serialize(writer, myStudent)
writer.Close()
' Create the XmlAttributeOverrides and XmlAttributes objects.
Dim myXmlBookAttributeOverrides As New XmlAttributeOverrides()
Dim myXmlBookAttributes As New XmlAttributes()
' Create an XmlAttributeAttribute set it to the XmlAttribute property of the XmlAttributes object.
Dim myXmlBookAttributeAttribute As New XmlAttributeAttribute("Name")
myXmlBookAttributes.XmlAttribute = myXmlBookAttributeAttribute
' Add to the XmlAttributeOverrides. Specify the member name.
myXmlBookAttributeOverrides.Add(GetType(Book), "BookName", myXmlBookAttributes)
' Create the XmlSerializer.
mySerializer = New XmlSerializer(GetType(Book), myXmlBookAttributeOverrides)
writer = New StreamWriter(bookFilename)
' Create an instance of the class that will be serialized.
Dim myBook As New Book()
' Set the Name property, which will be generated as an XML attribute.
myBook.BookName = ".NET"
myBook.BookNumber = 10
' Serialize the class, and close the TextWriter.
mySerializer.Serialize(writer, myBook)
writer.Close()
End Sub
End Class