DataContractSerializer 建構函式

定義

初始化 DataContractSerializer 類別的新執行個體。

多載

名稱 Description
DataContractSerializer(Type)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate, DataContractResolver)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構來保留圖中的物件參考資料、自訂序列化的替代者,以及指定包含內容的 XML 元素與命名空間的參數 XmlDictionaryString , 以及執行時映射 xsi:type 宣告的替代方案。

DataContractSerializer(Type, String, String, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate, DataContractResolver)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構來保留圖中的物件參考資料、自訂序列化的替代工具、包含內容的 XML 元素與命名空間, 以及執行時映射 xsi:type 宣告的替代方案。

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構來保留圖中的物件參考資料、自訂序列化的替代者,以及指定包含內容的 XML 元素與命名空間的參數 XmlDictionaryString

DataContractSerializer(Type, String, String, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構來保留圖中的物件參考資料、自訂序列化的替代者,以及包含內容的 XML 元素與命名空間。

DataContractSerializer(Type, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構來保留圖中的物件參考資料,以及自訂序列化的代理工具。

DataContractSerializer(Type, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate, DataContractResolver)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構以保留圖中的物件參考資料、自訂序列化的替代工具,以及執行時映射 xsi:type 宣告的替代方案。

DataContractSerializer(Type, String, String, IEnumerable<Type>)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定根 XML 元素與兩個字串參數的命名空間,以及物件圖中可能存在的已知類型清單。

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString)

初始化類別的新實例 DataContractSerializer ,利用 XML 根元素與命名空間,透過型別 XmlDictionaryString參數 來序列化或反序列化指定類型的物件。

DataContractSerializer(Type, String, String)

初始化該類別的新實例 DataContractSerializer ,利用提供的 XML 根元素與命名空間序列化或反序列化指定類型的物件。

DataContractSerializer(Type, DataContractSerializerSettings)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型與設定的物件。

DataContractSerializer(Type, IEnumerable<Type>)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件,以及可能存在於物件圖中的已知類型集合。

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString, IEnumerable<Type>)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定根 XML 元素與命名空間,包含兩個 XmlDictionaryString 參數,以及物件圖中可能存在的已知類型清單。

DataContractSerializer(Type)

來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。

public:
 DataContractSerializer(Type ^ type);
public DataContractSerializer(Type type);
new System.Runtime.Serialization.DataContractSerializer : Type -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type)

參數

type
Type

序列化或非序列化的實例類型。

範例

以下範例建立一個 的實例 DataContractSerializer ,指定要序列化或反序列化的類型。

public static void Constructor1()
{
    // Create an instance of the DataContractSerializer.
    DataContractSerializer ser =
        new DataContractSerializer(typeof(Person));
    // Other code not shown.
}
 Public Shared Sub Constructor1() 
     ' Create an instance of the DataContractSerializer.
     Dim ser As New DataContractSerializer(GetType(Person))

     ' Other code not shown.    
 End Sub

適用於

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate, DataContractResolver)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構來保留圖中的物件參考資料、自訂序列化的替代者,以及指定包含內容的 XML 元素與命名空間的參數 XmlDictionaryString , 以及執行時映射 xsi:type 宣告的替代方案。

public:
 DataContractSerializer(Type ^ type, System::Xml::XmlDictionaryString ^ rootName, System::Xml::XmlDictionaryString ^ rootNamespace, System::Collections::Generic::IEnumerable<Type ^> ^ knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System::Runtime::Serialization::IDataContractSurrogate ^ dataContractSurrogate, System::Runtime::Serialization::DataContractResolver ^ dataContractResolver);
public DataContractSerializer(Type type, System.Xml.XmlDictionaryString rootName, System.Xml.XmlDictionaryString rootNamespace, System.Collections.Generic.IEnumerable<Type> knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System.Runtime.Serialization.IDataContractSurrogate dataContractSurrogate, System.Runtime.Serialization.DataContractResolver dataContractResolver);
new System.Runtime.Serialization.DataContractSerializer : Type * System.Xml.XmlDictionaryString * System.Xml.XmlDictionaryString * seq<Type> * int * bool * bool * System.Runtime.Serialization.IDataContractSurrogate * System.Runtime.Serialization.DataContractResolver -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, rootName As XmlDictionaryString, rootNamespace As XmlDictionaryString, knownTypes As IEnumerable(Of Type), maxItemsInObjectGraph As Integer, ignoreExtensionDataObject As Boolean, preserveObjectReferences As Boolean, dataContractSurrogate As IDataContractSurrogate, dataContractResolver As DataContractResolver)

參數

type
Type

序列化或非序列化的實例類型。

rootName
XmlDictionaryString

包含內容以進行序列化或反序列化的 XML 元素。

rootNamespace
XmlDictionaryString

包圍內容以進行序列化或反序列化的 XML 元素命名空間。

knownTypes
IEnumerable<Type>

其中 an IEnumerable<T>Type 包含物件圖中可能存在的已知類型。

maxItemsInObjectGraph
Int32

圖中最多可序列化或反序列化的項目數量。

ignoreExtensionDataObject
Boolean

true忽略由該型別擴充在序列化與反序列化時所提供的資料;否則,。 false

preserveObjectReferences
Boolean

true使用非標準的 XML 結構來保存物件參考資料;否則,。 false

dataContractSurrogate
IDataContractSurrogate

一個用於自訂序列化流程的實作 IDataContractSurrogate

dataContractResolver
DataContractResolver

將 to 宣告映射DataContractResolver到資料合約類型的實作xsi:type

適用於

DataContractSerializer(Type, String, String, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate, DataContractResolver)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構來保留圖中的物件參考資料、自訂序列化的替代工具、包含內容的 XML 元素與命名空間, 以及執行時映射 xsi:type 宣告的替代方案。

public:
 DataContractSerializer(Type ^ type, System::String ^ rootName, System::String ^ rootNamespace, System::Collections::Generic::IEnumerable<Type ^> ^ knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System::Runtime::Serialization::IDataContractSurrogate ^ dataContractSurrogate, System::Runtime::Serialization::DataContractResolver ^ dataContractResolver);
public DataContractSerializer(Type type, string rootName, string rootNamespace, System.Collections.Generic.IEnumerable<Type> knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System.Runtime.Serialization.IDataContractSurrogate dataContractSurrogate, System.Runtime.Serialization.DataContractResolver dataContractResolver);
new System.Runtime.Serialization.DataContractSerializer : Type * string * string * seq<Type> * int * bool * bool * System.Runtime.Serialization.IDataContractSurrogate * System.Runtime.Serialization.DataContractResolver -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, rootName As String, rootNamespace As String, knownTypes As IEnumerable(Of Type), maxItemsInObjectGraph As Integer, ignoreExtensionDataObject As Boolean, preserveObjectReferences As Boolean, dataContractSurrogate As IDataContractSurrogate, dataContractResolver As DataContractResolver)

參數

type
Type

序列化或非序列化的實例類型。

rootName
String

包含內容以進行序列化或反序列化的 XML 元素。

rootNamespace
String

包圍內容以進行序列化或反序列化的 XML 元素命名空間。

knownTypes
IEnumerable<Type>

其中 an IEnumerable<T>Type 包含物件圖中可能存在的已知類型。

maxItemsInObjectGraph
Int32

圖中最多可序列化或反序列化的項目數量。

ignoreExtensionDataObject
Boolean

true忽略由該型別擴充在序列化與反序列化時所提供的資料;否則,。 false

preserveObjectReferences
Boolean

true使用非標準的 XML 結構來保存物件參考資料;否則,。 false

dataContractSurrogate
IDataContractSurrogate

一個用於自訂序列化流程的實作 IDataContractSurrogate

dataContractResolver
DataContractResolver

將 to 宣告映射DataContractResolver到資料合約類型的實作xsi:type

適用於

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構來保留圖中的物件參考資料、自訂序列化的替代者,以及指定包含內容的 XML 元素與命名空間的參數 XmlDictionaryString

public:
 DataContractSerializer(Type ^ type, System::Xml::XmlDictionaryString ^ rootName, System::Xml::XmlDictionaryString ^ rootNamespace, System::Collections::Generic::IEnumerable<Type ^> ^ knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System::Runtime::Serialization::IDataContractSurrogate ^ dataContractSurrogate);
public DataContractSerializer(Type type, System.Xml.XmlDictionaryString rootName, System.Xml.XmlDictionaryString rootNamespace, System.Collections.Generic.IEnumerable<Type> knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System.Runtime.Serialization.IDataContractSurrogate dataContractSurrogate);
new System.Runtime.Serialization.DataContractSerializer : Type * System.Xml.XmlDictionaryString * System.Xml.XmlDictionaryString * seq<Type> * int * bool * bool * System.Runtime.Serialization.IDataContractSurrogate -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, rootName As XmlDictionaryString, rootNamespace As XmlDictionaryString, knownTypes As IEnumerable(Of Type), maxItemsInObjectGraph As Integer, ignoreExtensionDataObject As Boolean, preserveObjectReferences As Boolean, dataContractSurrogate As IDataContractSurrogate)

參數

type
Type

序列化或非序列化的實例類型。

rootName
XmlDictionaryString

the XmlDictionaryString that 指定了包圍內容以進行序列化或反序列化的 XML 元素。

rootNamespace
XmlDictionaryString

XmlDictionaryString 個指定根節點的 XML 命名空間。

knownTypes
IEnumerable<Type>

其中 A IEnumerable<T>Type 包含物件圖中可能存在的已知類型。

maxItemsInObjectGraph
Int32

圖中最多可序列化或反序列化的項目數量。

ignoreExtensionDataObject
Boolean

true忽略由該型別擴充在序列化與反序列化時所提供的資料;否則,。 false

preserveObjectReferences
Boolean

true使用非標準的 XML 結構來保存物件參考資料;否則,。 false

dataContractSurrogate
IDataContractSurrogate

一個用於自訂序列化流程的實作 IDataContractSurrogate

例外狀況

物品數量超過最高價值。

範例

以下範例建立一個 的 DataContractSerializer 實例,指定要序列化或反序列化的類型、根 XML 元素與命名空間(作為 XmlDictionaryString 參數),以及一個包含反序列化期間使用的類型 的 a IEnumerable<T> 實例。 程式碼同時將 和 ignoreExtensionDataObject 參數設preserveObjectReferencestrue,並指定介面實作IDataContractSurrogate以處理遺留型別(未套用該DataContractAttribute屬性的型別)。 欲了解更多資訊,請參閱 IDataContractSurrogate 文件。

public static void Constructor9()
{
    // Create a generic List of types and add the known types
    // to the collection.
    List<Type> knownTypeList = new List<Type>();
    knownTypeList.Add(typeof(PurchaseOrder));
    knownTypeList.Add(typeof(PurchaseOrderV3));

    // Create an XmlDictionary and add values to it.
    XmlDictionary d = new XmlDictionary();
    XmlDictionaryString name_value = d.Add("Customer");
    XmlDictionaryString ns_value = d.Add("http://www.contoso.com");

    // Create an instance of a class that
    // implements the IDataContractSurrogate interface.
    // The implementation code is not shown here.
    DCSurrogate mySurrogate = new DCSurrogate();

    DataContractSerializer ser =
        new DataContractSerializer(
        typeof(Person),
        name_value,
        ns_value,
        knownTypeList,
        64 * 1024,
        true,
        true,
        mySurrogate);

    // Other code not shown.
}
Public Shared Sub Constructor9() 

    ' Create a generic List of types and add the known types
    ' to the collection.
    Dim knownTypeList As New List(Of Type)
    knownTypeList.Add(GetType(PurchaseOrder))
    knownTypeList.Add(GetType(PurchaseOrderV3))
    
    ' Create an XmlDictionary and add values to it.
    Dim d As New XmlDictionary()
    Dim name_value As XmlDictionaryString = d.Add("Customer")
    Dim ns_value As XmlDictionaryString = d.Add("http://www.contoso.com")
    
    ' Create an instance of a class that 
    ' implements the IDataContractSurrogate interface.
    ' The implementation code is not shown here.
    Dim mySurrogate As New DCSurrogate()
    
    Dim ser As New DataContractSerializer(GetType(Person), _
    name_value, _
    ns_value, _
    knownTypeList, _
    64 * 1064, _
    True, _
    True, _
    mySurrogate)

    ' Other code not shown.    

End Sub

另請參閱

適用於

DataContractSerializer(Type, String, String, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構來保留圖中的物件參考資料、自訂序列化的替代者,以及包含內容的 XML 元素與命名空間。

public:
 DataContractSerializer(Type ^ type, System::String ^ rootName, System::String ^ rootNamespace, System::Collections::Generic::IEnumerable<Type ^> ^ knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System::Runtime::Serialization::IDataContractSurrogate ^ dataContractSurrogate);
public DataContractSerializer(Type type, string rootName, string rootNamespace, System.Collections.Generic.IEnumerable<Type> knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System.Runtime.Serialization.IDataContractSurrogate dataContractSurrogate);
new System.Runtime.Serialization.DataContractSerializer : Type * string * string * seq<Type> * int * bool * bool * System.Runtime.Serialization.IDataContractSurrogate -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, rootName As String, rootNamespace As String, knownTypes As IEnumerable(Of Type), maxItemsInObjectGraph As Integer, ignoreExtensionDataObject As Boolean, preserveObjectReferences As Boolean, dataContractSurrogate As IDataContractSurrogate)

參數

type
Type

序列化或非序列化的實例類型。

rootName
String

包含內容以進行序列化或反序列化的 XML 元素。

rootNamespace
String

包圍內容以進行序列化或反序列化的 XML 元素命名空間。

knownTypes
IEnumerable<Type>

其中 an IEnumerable<T>Type 包含物件圖中可能存在的已知類型。

maxItemsInObjectGraph
Int32

圖中最多可序列化或反序列化的項目數量。

ignoreExtensionDataObject
Boolean

true忽略由該型別擴充在序列化與反序列化時所提供的資料;否則,。 false

preserveObjectReferences
Boolean

true使用非標準的 XML 結構來保存物件參考資料;否則,。 false

dataContractSurrogate
IDataContractSurrogate

一個用於自訂序列化流程的實作 IDataContractSurrogate

例外狀況

物品數量超過最高價值。

範例

以下範例建立一個 的 DataContractSerializer 實例,指定要序列化或反序列化的型別、根 XML 元素與命名空間,以及一個包含反序列化時所用型別的 a IEnumerable<T> 實例。 程式碼同時將 和 ignoreExtensionDataObject 參數設preserveObjectReferencestrue,並指定介面實作IDataContractSurrogate以處理遺留型別(未套用該DataContractAttribute屬性的型別)。 欲了解更多資訊,請參閱 IDataContractSurrogate 文件。

public static void Constructor8()
{
    // Create a generic List of types and add the known types
    // to the collection.
    List<Type> knownTypeList = new List<Type>();
    knownTypeList.Add(typeof(PurchaseOrder));
    knownTypeList.Add(typeof(PurchaseOrderV3));

    // Create an instance of a class that
    // implements the IDataContractSurrogate interface.
    // The implementation code is not shown here.
    DCSurrogate mySurrogate = new DCSurrogate();

    DataContractSerializer ser =
        new DataContractSerializer(
        typeof(Person),
        "Customer",
        @"http://www.contoso.com",
        knownTypeList,
        64 * 1024,
        true,
        true,
        mySurrogate);

    // Other code not shown.
}
Public Shared Sub Constructor8() 

    ' Create a generic List of types and add the known types
    ' to the collection.
    Dim knownTypeList As New List(Of Type)
    knownTypeList.Add(GetType(PurchaseOrder))
    knownTypeList.Add(GetType(PurchaseOrderV3))

    ' Create an instance of a class that 
    ' implements the IDataContractSurrogate interface.
    ' The implementation code is not shown here.
    Dim mySurrogate As New DCSurrogate()

    Dim ser As New DataContractSerializer(GetType(Person), _
    "Customer", _
    "http://www.contoso.com", _
    knownTypeList, _
    64 * 1064, _
    True, _
    True, _
    mySurrogate)

    ' Other code not shown.
End Sub

另請參閱

適用於

DataContractSerializer(Type, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構來保留圖中的物件參考資料,以及自訂序列化的代理工具。

public:
 DataContractSerializer(Type ^ type, System::Collections::Generic::IEnumerable<Type ^> ^ knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System::Runtime::Serialization::IDataContractSurrogate ^ dataContractSurrogate);
public DataContractSerializer(Type type, System.Collections.Generic.IEnumerable<Type> knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System.Runtime.Serialization.IDataContractSurrogate dataContractSurrogate);
new System.Runtime.Serialization.DataContractSerializer : Type * seq<Type> * int * bool * bool * System.Runtime.Serialization.IDataContractSurrogate -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, knownTypes As IEnumerable(Of Type), maxItemsInObjectGraph As Integer, ignoreExtensionDataObject As Boolean, preserveObjectReferences As Boolean, dataContractSurrogate As IDataContractSurrogate)

參數

type
Type

序列化或非序列化的實例類型。

knownTypes
IEnumerable<Type>

其中 an IEnumerable<T>Type 包含物件圖中可能存在的已知類型。

maxItemsInObjectGraph
Int32

圖中最多可序列化或反序列化的項目數量。 預設值是 Int32.MaxValue 屬性回傳的值。

ignoreExtensionDataObject
Boolean

true忽略由該型別擴充在序列化與反序列化時所提供的資料;否則,。 false

preserveObjectReferences
Boolean

true使用非標準的 XML 結構來保存物件參考資料;否則,。 false

dataContractSurrogate
IDataContractSurrogate

一個用於自訂序列化流程的實作 IDataContractSurrogate

例外狀況

物品數量超過最高價值。

範例

以下範例建立一個 的 DataContractSerializer 實例,指定要序列化或反序列化的類型,以及一個包含序列化或反序列化過程中已知型別的 a IEnumerable<T> 實例。 程式碼同時將 和 ignoreExtensionDataObject 參數設preserveObjectReferencestrue,並指定介面實作IDataContractSurrogate以處理遺留型別(未套用該DataContractAttribute屬性的型別)。 欲了解更多資訊,請參閱 IDataContractSurrogate 文件。

public static void Constructor7()
{
    // Create a generic List of types and add the known types
    // to the collection.
    List<Type> knownTypeList = new List<Type>();
    knownTypeList.Add(typeof(PurchaseOrder));
    knownTypeList.Add(typeof(PurchaseOrderV3));

    // Create an instance of a class that
    // implements the IDataContractSurrogate interface.
    // The implementation code is not shown here.
    DCSurrogate mySurrogate = new DCSurrogate();

    DataContractSerializer ser =
        new DataContractSerializer(
        typeof(Person),
        knownTypeList,
        64 * 1024,
        true,
        true,
        mySurrogate);
    // Other code not shown.
}
Public Shared Sub Constructor7() 

    ' Create a generic List of types and add the known types
    ' to the collection.
    Dim knownTypeList As New List(Of Type)
    knownTypeList.Add(GetType(PurchaseOrder))
    knownTypeList.Add(GetType(PurchaseOrderV3))

    ' Create an instance of a class that 
    ' implements the IDataContractSurrogate interface.
    ' The implementation code is not shown here.
    Dim mySurrogate As New DCSurrogate()

    Dim ser As New DataContractSerializer(GetType(Person), _
    knownTypeList, _
    64 * 1064, _
    True, _
    True, _
     mySurrogate)

    ' Other code not shown.
End Sub

另請參閱

適用於

DataContractSerializer(Type, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate, DataContractResolver)

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定物件圖中可能存在的已知類型清單、可序列化的最大圖項目數、忽略意外資料的參數、是否使用非標準 XML 結構以保留圖中的物件參考資料、自訂序列化的替代工具,以及執行時映射 xsi:type 宣告的替代方案。

public:
 DataContractSerializer(Type ^ type, System::Collections::Generic::IEnumerable<Type ^> ^ knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System::Runtime::Serialization::IDataContractSurrogate ^ dataContractSurrogate, System::Runtime::Serialization::DataContractResolver ^ dataContractResolver);
public DataContractSerializer(Type type, System.Collections.Generic.IEnumerable<Type> knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, System.Runtime.Serialization.IDataContractSurrogate dataContractSurrogate, System.Runtime.Serialization.DataContractResolver dataContractResolver);
new System.Runtime.Serialization.DataContractSerializer : Type * seq<Type> * int * bool * bool * System.Runtime.Serialization.IDataContractSurrogate * System.Runtime.Serialization.DataContractResolver -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, knownTypes As IEnumerable(Of Type), maxItemsInObjectGraph As Integer, ignoreExtensionDataObject As Boolean, preserveObjectReferences As Boolean, dataContractSurrogate As IDataContractSurrogate, dataContractResolver As DataContractResolver)

參數

type
Type

序列化或非序列化的實例類型。

knownTypes
IEnumerable<Type>

其中 an IEnumerable<T>Type 包含物件圖中可能存在的已知類型。

maxItemsInObjectGraph
Int32

圖中最多可序列化或反序列化的項目數量。 預設值是 Int32.MaxValue 屬性回傳的值。

ignoreExtensionDataObject
Boolean

true忽略由該型別擴充在序列化與反序列化時所提供的資料;否則,。 false

preserveObjectReferences
Boolean

true使用非標準的 XML 結構來保存物件參考資料;否則,。 false

dataContractSurrogate
IDataContractSurrogate

一個用於自訂序列化流程的實作 IDataContractSurrogate

dataContractResolver
DataContractResolver

將 to 宣告映射DataContractResolver到資料合約類型的實作xsi:type

備註

警告

此方法在 Windows 商店應用程式中無法使用。

適用於

DataContractSerializer(Type, String, String, IEnumerable<Type>)

來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定根 XML 元素與兩個字串參數的命名空間,以及物件圖中可能存在的已知類型清單。

public:
 DataContractSerializer(Type ^ type, System::String ^ rootName, System::String ^ rootNamespace, System::Collections::Generic::IEnumerable<Type ^> ^ knownTypes);
public DataContractSerializer(Type type, string rootName, string rootNamespace, System.Collections.Generic.IEnumerable<Type> knownTypes);
public DataContractSerializer(Type type, string rootName, string rootNamespace, System.Collections.Generic.IEnumerable<Type>? knownTypes);
new System.Runtime.Serialization.DataContractSerializer : Type * string * string * seq<Type> -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, rootName As String, rootNamespace As String, knownTypes As IEnumerable(Of Type))

參數

type
Type

序列化或非序列化的實例類型。

rootName
String

內容的根元素名稱。

rootNamespace
String

根元素的命名空間。

knownTypes
IEnumerable<Type>

其中 a IEnumerable<T>Type 包含了可能存在於物件圖中的類型。

範例

以下範例建立一個 的 DataContractSerializer 實例,指定要序列化或反序列化的類型,以及 XML 名稱與命名空間,用於讀取或寫入 XML 文件。 程式碼也會建立一個 的 IEnumerable<T> 實例,以包含序列化或反序列化過程中使用的已知型別。

public static void Constructor5()
{
    // Create a generic List of types and add the known types
    // to the collection.
    List<Type> knownTypeList = new List<Type>();
    knownTypeList.Add(typeof(PurchaseOrder));
    knownTypeList.Add(typeof(PurchaseOrderV3));

    DataContractSerializer ser =
        new DataContractSerializer(
        typeof(Person),
        "Customer",
        @"http://www.contoso.com",
        knownTypeList);

    // Other code not shown.
}
Public Shared Sub Constructor5() 

    ' Create a generic List of types and add the known types
    ' to the collection.
    Dim knownTypeList As New List(Of Type)
    knownTypeList.Add(GetType(PurchaseOrder))
    knownTypeList.Add(GetType(PurchaseOrderV3))
    
    Dim ser As New DataContractSerializer(GetType(Person), _
    "Customer", _
    "http://www.contoso.com", _
    knownTypeList)

    ' Other code not shown.

End Sub

另請參閱

適用於

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString)

來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs

初始化類別的新實例 DataContractSerializer ,利用 XML 根元素與命名空間,透過型別 XmlDictionaryString參數 來序列化或反序列化指定類型的物件。

public:
 DataContractSerializer(Type ^ type, System::Xml::XmlDictionaryString ^ rootName, System::Xml::XmlDictionaryString ^ rootNamespace);
public DataContractSerializer(Type type, System.Xml.XmlDictionaryString rootName, System.Xml.XmlDictionaryString rootNamespace);
new System.Runtime.Serialization.DataContractSerializer : Type * System.Xml.XmlDictionaryString * System.Xml.XmlDictionaryString -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, rootName As XmlDictionaryString, rootNamespace As XmlDictionaryString)

參數

type
Type

序列化或非序列化的實例類型。

rootName
XmlDictionaryString

一個 XmlDictionaryString 包含內容根元素名稱的 that。

rootNamespace
XmlDictionaryString

一個 XmlDictionaryString 包含根元素命名空間的 。

範例

以下範例建立一個 的 DataContractSerializer 實例,指定要序列化或反序列化的型別,以及 XML 名稱和命名空間(作為 XmlDictionaryString 物件)來讀取或寫入 XML 文件。

public static void Constructor4()
{
    // Create an instance of the DataContractSerializer
    // specifying the type, and name and
    // namespace as XmlDictionaryString objects.

    // Create an XmlDictionary and add values to it.
    XmlDictionary d = new XmlDictionary();
    XmlDictionaryString name_value = d.Add("Customer");
    XmlDictionaryString ns_value = d.Add("http://www.contoso.com");

    // Create the serializer.
    DataContractSerializer ser =
        new DataContractSerializer(
        typeof(Person),
        name_value,
        ns_value);
    // Other code not shown.
}
Public Shared Sub Constructor4() 
    ' Create an instance of the DataContractSerializer
    ' specifying the type, and name and 
    ' namespace as XmlDictionaryString objects.
    ' Create an XmlDictionary and add values to it.
    Dim d As New XmlDictionary()
    Dim name_value As XmlDictionaryString = d.Add("Customer")
    Dim ns_value As XmlDictionaryString = d.Add("http://www.contoso.com")
    
    ' Create the serializer.
    Dim ser As New DataContractSerializer(GetType(Person), _
    name_value, _
    ns_value)

    ' Other code not shown.
End Sub

適用於

DataContractSerializer(Type, String, String)

來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs

初始化該類別的新實例 DataContractSerializer ,利用提供的 XML 根元素與命名空間序列化或反序列化指定類型的物件。

public:
 DataContractSerializer(Type ^ type, System::String ^ rootName, System::String ^ rootNamespace);
public DataContractSerializer(Type type, string rootName, string rootNamespace);
new System.Runtime.Serialization.DataContractSerializer : Type * string * string -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, rootName As String, rootNamespace As String)

參數

type
Type

序列化或非序列化的實例類型。

rootName
String

包覆內容以進行序列化或反序列化的 XML 元素名稱。

rootNamespace
String

包圍內容以進行序列化或反序列化的 XML 元素命名空間。

範例

以下範例建立一個 的 DataContractSerializer 實例,指定要序列化或反序列化的類型,以及 XML 名稱與命名空間,用於讀取或寫入 XML 文件。

public static void Constructor3()
{
    // Create an instance of the DataContractSerializer
    // specifying the type, and name and
    // namespace as strings.
    DataContractSerializer ser =
        new DataContractSerializer(
        typeof(Person),
        "Customer",
        "http://www.contoso.com");

    // Other code not shown.
}
Public Shared Sub Constructor3() 
    ' Create an instance of the DataContractSerializer
    ' specifying the type, and name and 
    ' namespace as strings.
    Dim ser As New DataContractSerializer(GetType(Person), _
    "Customer", _
    "http://www.contoso.com")

    ' Other code not shown.
End Sub

適用於

DataContractSerializer(Type, DataContractSerializerSettings)

來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型與設定的物件。

public:
 DataContractSerializer(Type ^ type, System::Runtime::Serialization::DataContractSerializerSettings ^ settings);
public DataContractSerializer(Type type, System.Runtime.Serialization.DataContractSerializerSettings settings);
public DataContractSerializer(Type type, System.Runtime.Serialization.DataContractSerializerSettings? settings);
new System.Runtime.Serialization.DataContractSerializer : Type * System.Runtime.Serialization.DataContractSerializerSettings -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, settings As DataContractSerializerSettings)

參數

type
Type

序列化或反序列化的實例類型。

settings
DataContractSerializerSettings

串列器設定。

適用於

DataContractSerializer(Type, IEnumerable<Type>)

來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件,以及可能存在於物件圖中的已知類型集合。

public:
 DataContractSerializer(Type ^ type, System::Collections::Generic::IEnumerable<Type ^> ^ knownTypes);
public DataContractSerializer(Type type, System.Collections.Generic.IEnumerable<Type> knownTypes);
public DataContractSerializer(Type type, System.Collections.Generic.IEnumerable<Type>? knownTypes);
new System.Runtime.Serialization.DataContractSerializer : Type * seq<Type> -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, knownTypes As IEnumerable(Of Type))

參數

type
Type

序列化或非序列化的實例類型。

knownTypes
IEnumerable<Type>

其中 a IEnumerable<T>Type 包含了可能存在於物件圖中的類型。

範例

以下範例建立一個 的 DataContractSerializer 實例,指定要序列化或反序列化的類型,以及一組可用於物件圖的已知類型。

public static void Constructor2()
{
    // Create a generic List of types and add the known types
    // to the collection.
    List<Type> knownTypeList = new List<Type>();
    knownTypeList.Add(typeof(PurchaseOrder));
    knownTypeList.Add(typeof(PurchaseOrderV3));

    // Create a DatatContractSerializer with the collection.
    DataContractSerializer ser2 = new DataContractSerializer(
        typeof(Orders), knownTypeList);

    // Other code not shown.
}
 Public Shared Sub Constructor2() 

     ' Create a generic List of types and add the known types
     ' to the collection.
     Dim knownTypeList As New List(Of Type)
     knownTypeList.Add(GetType(PurchaseOrder))
     knownTypeList.Add(GetType(PurchaseOrderV3))
     
     ' Create a DatatContractSerializer with the collection.
     Dim ser2 As New DataContractSerializer(GetType(Orders), knownTypeList)

     ' Other code not shown.
End Sub

另請參閱

適用於

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString, IEnumerable<Type>)

來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs
來源:
DataContractSerializer.cs

初始化該類別的新實例 DataContractSerializer ,以序列化或反序列化指定類型的物件。 此方法同時指定根 XML 元素與命名空間,包含兩個 XmlDictionaryString 參數,以及物件圖中可能存在的已知類型清單。

public:
 DataContractSerializer(Type ^ type, System::Xml::XmlDictionaryString ^ rootName, System::Xml::XmlDictionaryString ^ rootNamespace, System::Collections::Generic::IEnumerable<Type ^> ^ knownTypes);
public DataContractSerializer(Type type, System.Xml.XmlDictionaryString rootName, System.Xml.XmlDictionaryString rootNamespace, System.Collections.Generic.IEnumerable<Type> knownTypes);
public DataContractSerializer(Type type, System.Xml.XmlDictionaryString rootName, System.Xml.XmlDictionaryString rootNamespace, System.Collections.Generic.IEnumerable<Type>? knownTypes);
new System.Runtime.Serialization.DataContractSerializer : Type * System.Xml.XmlDictionaryString * System.Xml.XmlDictionaryString * seq<Type> -> System.Runtime.Serialization.DataContractSerializer
Public Sub New (type As Type, rootName As XmlDictionaryString, rootNamespace As XmlDictionaryString, knownTypes As IEnumerable(Of Type))

參數

type
Type

序列化或非序列化的實例類型。

rootName
XmlDictionaryString

一個 XmlDictionaryString 包含內容根元素名稱的 that。

rootNamespace
XmlDictionaryString

一個 XmlDictionaryString 包含根元素命名空間的 。

knownTypes
IEnumerable<Type>

其中 A IEnumerable<T>Type 包含物件圖中可能存在的已知類型。

範例

以下範例建立一個 的 DataContractSerializer 實例,指定要序列化或反序列化的型別,以及 XML 名稱和命名空間(作為 XmlDictionaryString 物件)來讀取或寫入 XML 文件。 程式碼也會建立一個 的 IEnumerable<T> 實例,以包含序列化或反序列化過程中使用的已知型別。

public static void Constructor6()
{
    // Create a generic List of types and add the known types
    // to the collection.
    List<Type> knownTypeList = new List<Type>();
    knownTypeList.Add(typeof(PurchaseOrder));
    knownTypeList.Add(typeof(PurchaseOrderV3));

    // Create an XmlDictionary and add values to it.
    XmlDictionary d = new XmlDictionary();
    XmlDictionaryString name_value = d.Add("Customer");
    XmlDictionaryString ns_value = d.Add("http://www.contoso.com");

    DataContractSerializer ser =
        new DataContractSerializer(
        typeof(Person),
        name_value,
        ns_value,
        knownTypeList);

    // Other code not shown.
}
Public Shared Sub Constructor6() 
    ' Create a generic List of types and add the known types
    ' to the collection.
    Dim knownTypeList As New List(Of Type)
    knownTypeList.Add(GetType(PurchaseOrder))
    knownTypeList.Add(GetType(PurchaseOrderV3))

    ' Create an XmlDictionary and add values to it.
    Dim d As New XmlDictionary()
    Dim name_value As XmlDictionaryString = d.Add("Customer")
    Dim ns_value As XmlDictionaryString = d.Add("http://www.contoso.com")
    
    Dim ser As New DataContractSerializer(GetType(Person), _
    name_value, _
    ns_value, _
    knownTypeList)

    ' Other code not shown.
 End Sub

另請參閱

適用於