本文整理汇总了VB.NET中System.Xml.Serialization.XmlTextAttribute类的典型用法代码示例。如果您正苦于以下问题:VB.NET XmlTextAttribute类的具体用法?VB.NET XmlTextAttribute怎么用?VB.NET XmlTextAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XmlTextAttribute类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Group1
' 导入命名空间
Imports System.Xml.Serialization
Imports System.IO
Public Class Group1
' The XmlTextAttribute with type set to String informs the
' XmlSerializer that strings should be serialized as XML text.
<XmlText(GetType(String)), _
XmlElement(GetType(integer)), _
XmlElement(GetType(double))> _
public All () As Object = _
New Object (){321, "One", 2, 3.0, "Two" }
End Class
Public Class Group2
<XmlText(GetType(GroupType))> _
public Type As GroupType
End Class
Public Enum GroupType
Small
Medium
Large
End Enum
Public Class Group3
<XmlText(GetType(DateTime))> _
Public CreationTime As DateTime = DateTime.Now
End Class
Public Class Test
Shared Sub Main()
Dim t As Test = New Test()
t.SerializeArray("XmlText1.xml")
t.SerializeEnum("XmlText2.xml")
t.SerializeDateTime("XmlText3.xml")
End Sub
Private Sub SerializeArray(filename As String)
Dim ser As XmlSerializer = New XmlSerializer(GetType(Group1))
Dim myGroup1 As Group1 = New Group1()
Dim writer As TextWriter = New StreamWriter(filename)
ser.Serialize(writer, myGroup1)
writer.Close()
End Sub
Private Sub SerializeEnum(filename As String)
Dim ser As XmlSerializer = New XmlSerializer(GetType(Group2))
Dim myGroup As Group2 = New Group2()
myGroup.Type = GroupType.Medium
Dim writer As TextWriter = New StreamWriter(filename)
ser.Serialize(writer, myGroup)
writer.Close()
End Sub
Private Sub SerializeDateTime(filename As String)
Dim ser As XmlSerializer = new XmlSerializer(GetType(Group3))
Dim myGroup As Group3 = new Group3()
Dim writer As TextWriter = new StreamWriter(filename)
ser.Serialize(writer, myGroup)
writer.Close()
End Sub
End Class
示例2: textField
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlRootAttribute([Namespace]:="", IsNullable:=False)> _
Partial Public Class LinkList
Private idField As Integer
Private nameField As String
Private nextField As LinkList
Private textField() As String
Public Property id() As Integer
Get
Return Me.idField
End Get
Set(ByVal value As Integer)
Me.idField = value
End Set
End Property
Public Property name() As String
Get
Return Me.nameField
End Get
Set(ByVal value As String)
Me.nameField = value
End Set
End Property
Public Property [next]() As LinkList
Get
Return Me.nextField
End Get
Set(ByVal value As LinkList)
Me.nextField = value
End Set
End Property
<System.Xml.Serialization.XmlTextAttribute()> _
Public Property Text() As String()
Get
Return Me.textField
End Get
Set(ByVal value As String())
Me.textField = value
End Set
End Property
End Class