Converter 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表設定檔中的一個設定元素。
public ref class Converter : System::Configuration::ConfigurationElement
public class Converter : System.Configuration.ConfigurationElement
type Converter = class
inherit ConfigurationElement
Public Class Converter
Inherits ConfigurationElement
- 繼承
範例
以下設定檔摘錄展示了如何宣告式地指定類別屬性 Converter 的值。
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization>
<converters>
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter" />
</converters>
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
以下範例示範如何以程式化方式存取 Converter 。
// Get the Web application configuration.
System.Configuration.Configuration configuration =
WebConfigurationManager.OpenWebConfiguration("/aspnetTest");
// Get the external JSON section.
ScriptingJsonSerializationSection jsonSection =
(ScriptingJsonSerializationSection)configuration.GetSection(
"system.web.extensions/scripting/webServices/jsonSerialization");
//Get the converters collection.
ConvertersCollection converters =
jsonSection.Converters;
if ((converters != null) && converters.Count > 0)
{
// Get the first registered converter.
Converter converterElement = converters[0];
}
' Get the Web application configuration.
Dim configuration As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration("/aspnetTest")
' Get the external JSON section.
Dim jsonSection As ScriptingJsonSerializationSection = _
CType(configuration.GetSection( _
"system.web.extensions/scripting/webServices/jsonSerialization"), _
ScriptingJsonSerializationSection)
'Get the converters collection.
Dim converters As ConvertersCollection = _
jsonSection.Converters
If Not (converters Is Nothing) AndAlso _
converters.Count > 0 Then
' Get the first registered converter.
Dim converterElement As Converter = converters(0)
End If
備註
Converter類別允許您程式化存取並修改與 AJAX 啟用的 ASP.NET 應用程式所使用的轉換器相關的設定。
要建立自訂轉換功能,你可以建立一個繼承自該 JavaScriptConverter 類別的類別。 轉換器建立完成後,你可以將其註冊到網頁應用程式的設定檔中使用。
建構函式
| 名稱 | Description |
|---|---|
| Converter() |
初始化 Converter 類別的新執行個體。 |