-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathJavaScriptConverter.xml
More file actions
197 lines (174 loc) · 17.8 KB
/
JavaScriptConverter.xml
File metadata and controls
197 lines (174 loc) · 17.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<Type Name="JavaScriptConverter" FullName="System.Web.Script.Serialization.JavaScriptConverter">
<TypeSignature Language="C#" Value="public abstract class JavaScriptConverter" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract beforefieldinit JavaScriptConverter extends System.Object" />
<TypeSignature Language="DocId" Value="T:System.Web.Script.Serialization.JavaScriptConverter" />
<TypeSignature Language="VB.NET" Value="Public MustInherit Class JavaScriptConverter" />
<TypeSignature Language="F#" Value="type JavaScriptConverter = class" />
<TypeSignature Language="C++ CLI" Value="public ref class JavaScriptConverter abstract" />
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>Provides an abstract base class for a custom type converter.</summary>
<remarks>
<format type="text/markdown"><).
When the <xref:System.Web.Script.Serialization.JavaScriptSerializer> instance is serializing a type for which it has a custom converter registered, the serializer calls the <xref:System.Web.Script.Serialization.JavaScriptConverter.Serialize%2A> method. Similarly, when the <xref:System.Web.Script.Serialization.JavaScriptSerializer> instance is deserializing a JavaScript Object Notation (JSON) string and recognizes that a type inside the JSON string has a custom converter associated with it, the serializer calls the <xref:System.Web.Script.Serialization.JavaScriptConverter.Deserialize%2A> method.
## Examples
The following example shows how to create a custom converter for the <xref:System.Web.UI.WebControls.ListItemCollection> class.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_Atlas/System.Web.Script.Serialization/CS/App_Code/ListItemCollectionConverter.cs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Atlas/System.Web.Script.Serialization/VB/App_Code/ListItemCollectionConverter.vb" id="Snippet2":::
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>When you inherit from <see cref="T:System.Web.Script.Serialization.JavaScriptConverter" />, you must override the following members:
- <see cref="M:System.Web.Script.Serialization.JavaScriptConverter.Deserialize(System.Collections.Generic.IDictionary{System.String,System.Object},System.Type,System.Web.Script.Serialization.JavaScriptSerializer)" />
- <see cref="M:System.Web.Script.Serialization.JavaScriptConverter.Serialize(System.Object,System.Web.Script.Serialization.JavaScriptSerializer)" />
- <see cref="P:System.Web.Script.Serialization.JavaScriptConverter.SupportedTypes" /><see cref="T:System.Web.Script.Serialization.JavaScriptSerializer" /> provides the <see cref="M:System.Web.Script.Serialization.JavaScriptSerializer.ConvertToType``1(System.Object)" /> method that will be used by implementers of <see cref="T:System.Web.Script.Serialization.JavaScriptConverter" />. Converter code must be able to take a value that is contained in the dictionary that the serializer passes to it, and then convert that value into an object of type <paramref name="T" />. Rather than re-implementing the custom conversion code to accomplish this, you can call the <see cref="M:System.Web.Script.Serialization.JavaScriptSerializer.ConvertToType``1(System.Object)" /> method.</para>
</block>
<altmember cref="T:System.Web.Configuration.Converter" />
<related type="Article" href="https://msdn.microsoft.com/library/8290e543-7eff-47a4-aace-681f3c07229b">Web Services in ASP.NET AJAX</related>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="protected JavaScriptConverter ();" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Script.Serialization.JavaScriptConverter.#ctor" />
<MemberSignature Language="VB.NET" Value="Protected Sub New ()" />
<MemberSignature Language="C++ CLI" Value="protected:
 JavaScriptConverter();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Web.Script.Serialization.JavaScriptConverter" /> class.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Deserialize">
<MemberSignature Language="C#" Value="public abstract object Deserialize (System.Collections.Generic.IDictionary<string,object> dictionary, Type type, System.Web.Script.Serialization.JavaScriptSerializer serializer);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance object Deserialize(class System.Collections.Generic.IDictionary`2<string, object> dictionary, class System.Type type, class System.Web.Script.Serialization.JavaScriptSerializer serializer) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Script.Serialization.JavaScriptConverter.Deserialize(System.Collections.Generic.IDictionary{System.String,System.Object},System.Type,System.Web.Script.Serialization.JavaScriptSerializer)" />
<MemberSignature Language="VB.NET" Value="Public MustOverride Function Deserialize (dictionary As IDictionary(Of String, Object), type As Type, serializer As JavaScriptSerializer) As Object" />
<MemberSignature Language="F#" Value="abstract member Deserialize : System.Collections.Generic.IDictionary<string, obj> * Type * System.Web.Script.Serialization.JavaScriptSerializer -> obj" Usage="javaScriptConverter.Deserialize (dictionary, type, serializer)" />
<MemberSignature Language="C++ CLI" Value="public:
 abstract System::Object ^ Deserialize(System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ dictionary, Type ^ type, System::Web::Script::Serialization::JavaScriptSerializer ^ serializer);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Object</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="dictionary" Type="System.Collections.Generic.IDictionary<System.String,System.Object>" />
<Parameter Name="type" Type="System.Type" />
<Parameter Name="serializer" Type="System.Web.Script.Serialization.JavaScriptSerializer" />
</Parameters>
<Docs>
<param name="dictionary">An <see cref="T:System.Collections.Generic.IDictionary`2" /> instance of property data stored as name/value pairs.</param>
<param name="type">The type of the resulting object.</param>
<param name="serializer">The <see cref="T:System.Web.Script.Serialization.JavaScriptSerializer" /> instance.</param>
<summary>When overridden in a derived class, converts the provided dictionary into an object of the specified type.</summary>
<returns>The deserialized object.</returns>
<remarks>To be added.</remarks>
<block subset="none" type="overrides">
<para>The <see cref="M:System.Web.Script.Serialization.JavaScriptConverter.Deserialize(System.Collections.Generic.IDictionary{System.String,System.Object},System.Type,System.Web.Script.Serialization.JavaScriptSerializer)" /> method iterates through the values in the <paramref name="dictionary" /> parameter to construct an instance of the type requested in the <paramref name="type" /> parameter. Although a converter can directly use values from <paramref name="dictionary" />, we recommend that the converter implementer use the <see cref="M:System.Web.Script.Serialization.JavaScriptSerializer.ConvertToType``1(System.Object)" /> method instead. The converter should call this method of the <see cref="T:System.Web.Script.Serialization.JavaScriptSerializer" /> instance available from the <paramref name="serializer" /> parameter.
The <see cref="M:System.Web.Script.Serialization.JavaScriptSerializer.ConvertToType``1(System.Object)" /> method enables converter to pass a property value from <paramref name="dictionary" />, and then return a value of the expected type. In some cases, a converter for a custom type might be working with properties that themselves have registered converters (for example, type A has a property of type B, and type B is also associated with a custom converter). In that case, invoking <see cref="M:System.Web.Script.Serialization.JavaScriptSerializer.ConvertToType``1(System.Object)" /> makes sure that custom converters will be recursively invoked for property data that is contained in the dictionary. When the converter has iterated through all entries in the dictionary, it returns a constructed instance of the target type.
If the converter encounters a problem during deserialization, it should throw an <see cref="T:System.InvalidOperationException" /> error that describes the problem.</para>
</block>
</Docs>
</Member>
<Member MemberName="Serialize">
<MemberSignature Language="C#" Value="public abstract System.Collections.Generic.IDictionary<string,object> Serialize (object obj, System.Web.Script.Serialization.JavaScriptSerializer serializer);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance class System.Collections.Generic.IDictionary`2<string, object> Serialize(object obj, class System.Web.Script.Serialization.JavaScriptSerializer serializer) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Script.Serialization.JavaScriptConverter.Serialize(System.Object,System.Web.Script.Serialization.JavaScriptSerializer)" />
<MemberSignature Language="VB.NET" Value="Public MustOverride Function Serialize (obj As Object, serializer As JavaScriptSerializer) As IDictionary(Of String, Object)" />
<MemberSignature Language="F#" Value="abstract member Serialize : obj * System.Web.Script.Serialization.JavaScriptSerializer -> System.Collections.Generic.IDictionary<string, obj>" Usage="javaScriptConverter.Serialize (obj, serializer)" />
<MemberSignature Language="C++ CLI" Value="public:
 abstract System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ Serialize(System::Object ^ obj, System::Web::Script::Serialization::JavaScriptSerializer ^ serializer);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Collections.Generic.IDictionary<System.String,System.Object></ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="obj" Type="System.Object" />
<Parameter Name="serializer" Type="System.Web.Script.Serialization.JavaScriptSerializer" />
</Parameters>
<Docs>
<param name="obj">The object to serialize.</param>
<param name="serializer">The object that is responsible for the serialization.</param>
<summary>When overridden in a derived class, builds a dictionary of name/value pairs.</summary>
<returns>An object that contains key/value pairs that represent the object's data.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
When you serialize a type for which a custom converter is registered, the <xref:System.Web.Script.Serialization.JavaScriptSerializer> instance invokes the <xref:System.Web.Script.Serialization.JavaScriptConverter.Serialize%2A> method.
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>The return value of <see cref="M:System.Web.Script.Serialization.JavaScriptConverter.Serialize(System.Object,System.Web.Script.Serialization.JavaScriptSerializer)" /> must be an <see cref="T:System.Collections.Generic.IDictionary`2" /> instance with zero or more name/value pairs that represent an object's data to be converted to JSON. The converter itself does not serialize data as JSON. Instead, the converter builds a dictionary of name/value pairs that contain the property names (the string key for the dictionary) and corresponding property values (the object value in the dictionary). The <see cref="T:System.Web.Script.Serialization.JavaScriptSerializer" /> instance subsequently converts these to JSON.
If the converter encounters an exception, it should throw an <see cref="T:System.InvalidOperationException" /> error that describes the problem.</para>
</block>
</Docs>
</Member>
<Member MemberName="SupportedTypes">
<MemberSignature Language="C#" Value="public abstract System.Collections.Generic.IEnumerable<Type> SupportedTypes { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Collections.Generic.IEnumerable`1<class System.Type> SupportedTypes" />
<MemberSignature Language="DocId" Value="P:System.Web.Script.Serialization.JavaScriptConverter.SupportedTypes" />
<MemberSignature Language="VB.NET" Value="Public MustOverride ReadOnly Property SupportedTypes As IEnumerable(Of Type)" />
<MemberSignature Language="F#" Value="member this.SupportedTypes : seq<Type>" Usage="System.Web.Script.Serialization.JavaScriptConverter.SupportedTypes" />
<MemberSignature Language="C++ CLI" Value="public:
 abstract property System::Collections::Generic::IEnumerable<Type ^> ^ SupportedTypes { System::Collections::Generic::IEnumerable<Type ^> ^ get(); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Collections.Generic.IEnumerable<System.Type></ReturnType>
</ReturnValue>
<Docs>
<summary>When overridden in a derived class, gets a collection of the supported types.</summary>
<value>An object that implements <see cref="T:System.Collections.Generic.IEnumerable`1" /> that represents the types supported by the converter.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Script.Serialization.JavaScriptConverter.SupportedTypes> property lists the types that are supported by the converter. At run time, a <xref:System.Web.Script.Serialization.JavaScriptSerializer> instance uses this property to determine the mapping of managed types to their corresponding custom converters.
## Examples
The following example shows how to override the <xref:System.Web.Script.Serialization.JavaScriptConverter.SupportedTypes> property in a derived class. In this example, the converter supports only the <xref:System.Web.UI.WebControls.ListItemCollection> type. This code example is part of a larger example provided for the <xref:System.Web.Script.Serialization.JavaScriptConverter> class.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_Atlas/System.Web.Script.Serialization/CS/App_Code/ListItemCollectionConverter.cs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Atlas/System.Web.Script.Serialization/VB/App_Code/ListItemCollectionConverter.vb" id="Snippet3":::
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>
<see cref="P:System.Web.Script.Serialization.JavaScriptConverter.SupportedTypes" /> must always return a collection, and the collection must contain at least one entry.</para>
</block>
</Docs>
</Member>
</Members>
</Type>