本文整理汇总了VB.NET中System.Xml.Serialization.XmlAttributes.XmlAttribute属性的典型用法代码示例。如果您正苦于以下问题:VB.NET XmlAttributes.XmlAttribute属性的具体用法?VB.NET XmlAttributes.XmlAttribute怎么用?VB.NET XmlAttributes.XmlAttribute使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Xml.Serialization.XmlAttributes 的用法示例。
在下文中一共展示了XmlAttributes.XmlAttribute属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Group
' 导入命名空间
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
' This is the class that will be serialized.
Public Class Group
' This is the attribute that will be overridden.
<XmlAttribute()> Public GroupName As String
Public GroupNumber As Integer
End Class
Public Class Run
Public Shared Sub Main()
Dim test As New Run()
test.SerializeObject("OverrideAttribute.xml")
test.DeserializeObject("OverrideAttribute.xml")
End Sub
' Return an XmlSerializer used for overriding.
Public Function CreateOverrider() As XmlSerializer
' Create the XmlAttributeOverrides and XmlAttributes objects.
Dim xOver As New XmlAttributeOverrides()
Dim xAttrs As New XmlAttributes()
' Create an overriding XmlAttributeAttribute set it to
' the XmlAttribute property of the XmlAttributes object.
Dim xAttribute As New XmlAttributeAttribute("SplinterName")
xAttrs.XmlAttribute = xAttribute
' Add to the XmlAttributeOverrides. Specify the member name.
xOver.Add(GetType(Group), "GroupName", xAttrs)
' Create the XmlSerializer and return it.
Return New XmlSerializer(GetType(Group), xOver)
End Function 'CreateOverrider
Public Sub SerializeObject(ByVal filename As String)
' Create an instance of the XmlSerializer class.
Dim mySerializer As XmlSerializer = CreateOverrider()
' Writing the file requires a TextWriter.
Dim writer As New StreamWriter(filename)
' Create an instance of the class that will be serialized.
Dim myGroup As New Group()
' Set the Name property, which will be generated
' as an XML attribute.
myGroup.GroupName = ".NET"
myGroup.GroupNumber = 1
' Serialize the class, and close the TextWriter.
mySerializer.Serialize(writer, myGroup)
writer.Close()
End Sub
Public Sub DeserializeObject(ByVal filename As String)
Dim mySerializer As XmlSerializer = CreateOverrider()
Dim fs As New FileStream(filename, FileMode.Open)
Dim myGroup As Group = CType(mySerializer.Deserialize(fs), Group)
Console.WriteLine(myGroup.GroupName)
Console.WriteLine(myGroup.GroupNumber)
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Xml.Serialization,代码行数:69,代码来源:XmlAttributes.XmlAttribute
注:本文中的System.Xml.Serialization.XmlAttributes.XmlAttribute属性示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论