本文整理汇总了VB.NET中System.Web.Script.Serialization.JavaScriptConverter类的典型用法代码示例。如果您正苦于以下问题:VB.NET JavaScriptConverter类的具体用法?VB.NET JavaScriptConverter怎么用?VB.NET JavaScriptConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JavaScriptConverter类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: SupportedTypes
' 导入命名空间
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Web.UI.WebControls
Imports System.Collections
Namespace System.Web.Script.Serialization.VB
Public Class ListItemCollectionConverter
Inherits JavaScriptConverter
Public Overrides ReadOnly Property SupportedTypes() As _
System.Collections.Generic.IEnumerable(Of System.Type)
Get
' Define the ListItemCollection as a supported type.
Return New ReadOnlyCollection(Of Type)(New List(Of Type) _
(New Type() {GetType(ListItemCollection)}))
End Get
End Property
Public Overrides Function Serialize(ByVal obj As Object, _
ByVal serializer As JavaScriptSerializer) As _
System.Collections.Generic.IDictionary(Of String, Object)
Dim listType As ListItemCollection = CType(obj, ListItemCollection)
If Not (listType Is Nothing) Then
' Create the representation.
Dim result As New Dictionary(Of String, Object)
Dim itemsList As New ArrayList()
Dim item As ListItem
For Each item In listType
' Add each entry to the dictionary.
Dim listDict As New Dictionary(Of String, Object)
listDict.Add("Value", item.Value)
listDict.Add("Text", item.Text)
itemsList.Add(listDict)
Next item
result("List") = itemsList
Return result
End If
Return New Dictionary(Of String, Object)
End Function
Public Overrides Function Deserialize(ByVal dictionary As _
System.Collections.Generic.IDictionary(Of String, Object), _
ByVal type As System.Type, ByVal serializer As JavaScriptSerializer) As Object
If dictionary Is Nothing Then
Throw New ArgumentNullException("dictionary")
End If
If type Is GetType(ListItemCollection) Then
' Create the instance to deserialize into.
Dim list As New ListItemCollection()
' Deserialize the ListItemCollection's items.
Dim itemsList As ArrayList = CType(dictionary("List"), ArrayList)
Dim i As Integer
For i = 0 To itemsList.Count - 1
list.Add(serializer.ConvertToType(Of ListItem)(itemsList(i)))
Next i
Return list
End If
Return Nothing
End Function
End Class
End Namespace
开发者ID:VB.NET开发者,项目名称:System.Web.Script.Serialization,代码行数:74,代码来源:JavaScriptConverter
注:本文中的System.Web.Script.Serialization.JavaScriptConverter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论