DataContractSerializer コンストラクター

定義

DataContractSerializer クラスの新しいインスタンスを初期化します。

オーバーロード

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 ルート要素と名前空間を示す 2 つの文字列パラメーターと、オブジェクト グラフ内に存在可能な既知の型のリストを指定します。

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString)

DataContractSerializer クラスの新しいインスタンスを初期化し、指定した型のオブジェクトを、XmlDictionaryString のパラメーターを通して指定した XML ルート要素と名前空間を使用してシリアル化または逆シリアル化します。

DataContractSerializer(Type, String, String)

DataContractSerializer クラスの新しいインスタンスを初期化し、指定した型のオブジェクトを、指定した XML ルート要素と名前空間を使用してシリアル化または逆シリアル化します。

DataContractSerializer(Type, DataContractSerializerSettings)

指定した型と設定をシリアル化または逆シリアル化する DataContractSerializer クラスの新しいインスタンスを初期化します。

DataContractSerializer(Type, IEnumerable<Type>)

DataContractSerializer クラスの新しいインスタンスを初期化し、指定した型のオブジェクトと、オブジェクト グラフ内に存在可能な既知の型のコレクションをシリアル化または逆シリアル化します。

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

DataContractSerializer クラスの新しいインスタンスを初期化し、指定した型のオブジェクトをシリアル化または逆シリアル化します。 このメソッドは、さらに、XML ルート要素と名前空間を示す 2 つの XmlDictionaryString パラメーターと、オブジェクト グラフ内に存在可能な既知の型のリストを指定します。

DataContractSerializer(Type)

ソース:
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>

オブジェクト グラフ内に存在可能な既知の型を含む IEnumerable<T>Type

maxItemsInObjectGraph
Int32

シリアル化または逆シリアル化するグラフ内の項目の最大数。

ignoreExtensionDataObject
Boolean

シリアル化および逆シリアル化時に種類の拡張機能により提供されるデータを無視する場合は true。それ以外の場合は false

preserveObjectReferences
Boolean

オブジェクトの参照データを保持するために非標準の XML コンストラクトを使用する場合は true。それ以外の場合は false

dataContractSurrogate
IDataContractSurrogate

シリアル化処理をカスタマイズするための IDataContractSurrogate の実装。

dataContractResolver
DataContractResolver

xsi:type 宣言をデータ コントラクト型にマップする DataContractResolver の実装。

適用対象

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>

オブジェクト グラフ内に存在可能な既知の型を含む IEnumerable<T>Type

maxItemsInObjectGraph
Int32

シリアル化または逆シリアル化するグラフ内の項目の最大数。

ignoreExtensionDataObject
Boolean

シリアル化および逆シリアル化時に種類の拡張機能により提供されるデータを無視する場合は true。それ以外の場合は false

preserveObjectReferences
Boolean

オブジェクトの参照データを保持するために非標準の XML コンストラクトを使用する場合は true。それ以外の場合は false

dataContractSurrogate
IDataContractSurrogate

シリアル化処理をカスタマイズするための IDataContractSurrogate の実装。

dataContractResolver
DataContractResolver

xsi:type 宣言をデータ コントラクト型にマップする DataContractResolver の実装。

適用対象

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

シリアル化または逆シリアル化するコンテンツを囲む XML 要素を指定する XmlDictionaryString

rootNamespace
XmlDictionaryString

ルートの XML 名前空間を指定する XmlDictionaryString

knownTypes
IEnumerable<Type>

オブジェクト グラフ内に存在可能な既知の型を含む IEnumerable<T>Type

maxItemsInObjectGraph
Int32

シリアル化または逆シリアル化するグラフ内の項目の最大数。

ignoreExtensionDataObject
Boolean

シリアル化および逆シリアル化時に種類の拡張機能により提供されるデータを無視する場合は true。それ以外の場合は false

preserveObjectReferences
Boolean

オブジェクトの参照データを保持するために非標準の XML コンストラクトを使用する場合は true。それ以外の場合は false

dataContractSurrogate
IDataContractSurrogate

シリアル化処理をカスタマイズするための IDataContractSurrogate の実装。

例外

項目数が最大値を超えています。

次の例では、シリアル化または逆シリアル化する型、XML のルート要素と名前空間 (DataContractSerializer パラメーターとして)、および逆シリアル化の間に使用される型を含む XmlDictionaryString のインスタンスを指定する、IEnumerable<T> のインスタンスを作成します。 また、このコードでは、 パラメーターと preserveObjectReferences パラメーターを にtrue設定ignoreExtensionDataObjectし、レガシ型 (属性が適用されていない型) を処理するインターフェイスの実装IDataContractSurrogateDataContractAttribute指定します。 詳細については、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>

オブジェクト グラフ内に存在可能な既知の型を含む IEnumerable<T>Type

maxItemsInObjectGraph
Int32

シリアル化または逆シリアル化するグラフ内の項目の最大数。

ignoreExtensionDataObject
Boolean

シリアル化および逆シリアル化時に種類の拡張機能により提供されるデータを無視する場合は true。それ以外の場合は false

preserveObjectReferences
Boolean

オブジェクトの参照データを保持するために非標準の XML コンストラクトを使用する場合は true。それ以外の場合は false

dataContractSurrogate
IDataContractSurrogate

シリアル化処理をカスタマイズするための IDataContractSurrogate の実装。

例外

項目数が最大値を超えています。

次の例では、シリアル化または逆シリアル化する型、XML のルート要素と名前空間、および逆シリアル化の間に使用される型を含む DataContractSerializer のインスタンスを指定する、IEnumerable<T> のインスタンスを作成します。 また、このコードでは、 パラメーターと preserveObjectReferences パラメーターを にtrue設定ignoreExtensionDataObjectし、レガシ型 (属性が適用されていない型) を処理するインターフェイスの実装IDataContractSurrogateDataContractAttribute指定します。 詳細については、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>

オブジェクト グラフ内に存在可能な既知の型を含む IEnumerable<T>Type

maxItemsInObjectGraph
Int32

シリアル化または逆シリアル化するグラフ内の項目の最大数。 既定値は 、Int32.MaxValue プロパティによって返される値です。

ignoreExtensionDataObject
Boolean

シリアル化および逆シリアル化時に種類の拡張機能により提供されるデータを無視する場合は true。それ以外の場合は false

preserveObjectReferences
Boolean

オブジェクトの参照データを保持するために非標準の XML コンストラクトを使用する場合は true。それ以外の場合は false

dataContractSurrogate
IDataContractSurrogate

シリアル化処理をカスタマイズするための IDataContractSurrogate の実装。

例外

項目数が最大値を超えています。

次の例では、シリアル化または逆シリアル化する型と、シリアル化または逆シリアル化の間に使用される既知の型を含む DataContractSerializer のインスタンスを指定する、IEnumerable<T> のインスタンスを作成します。 また、このコードでは、 パラメーターと preserveObjectReferences パラメーターを にtrue設定ignoreExtensionDataObjectし、レガシ型 (属性が適用されていない型) を処理するインターフェイスの実装IDataContractSurrogateDataContractAttribute指定します。 詳細については、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>

オブジェクト グラフ内に存在可能な既知の型を含む IEnumerable<T>Type

maxItemsInObjectGraph
Int32

シリアル化または逆シリアル化するグラフ内の項目の最大数。 既定値は 、Int32.MaxValue プロパティによって返される値です。

ignoreExtensionDataObject
Boolean

シリアル化および逆シリアル化時に種類の拡張機能により提供されるデータを無視する場合は true。それ以外の場合は false

preserveObjectReferences
Boolean

オブジェクトの参照データを保持するために非標準の XML コンストラクトを使用する場合は true。それ以外の場合は false

dataContractSurrogate
IDataContractSurrogate

シリアル化処理をカスタマイズするための IDataContractSurrogate の実装。

dataContractResolver
DataContractResolver

xsi:type 宣言をデータ コントラクト型にマップする DataContractResolver の実装。

注釈

警告

この方法は、Windows ストア アプリでは使用できません。

適用対象

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

ソース:
DataContractSerializer.cs
ソース:
DataContractSerializer.cs
ソース:
DataContractSerializer.cs

DataContractSerializer クラスの新しいインスタンスを初期化し、指定した型のオブジェクトをシリアル化または逆シリアル化します。 このメソッドは、さらに、XML ルート要素と名前空間を示す 2 つの文字列パラメーターと、オブジェクト グラフ内に存在可能な既知の型のリストを指定します。

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>

オブジェクト グラフ内に存在可能な型を含む IEnumerable<T>Type

次の例は、シリアル化または逆シリアル化する型と、XML ドキュメントに対して読み取りまたは書き込みを行う XML 名と名前空間を指定する DataContractSerializer のインスタンスを作成します。 このコードはまた、シリアル化または逆シリアル化で使用される既知の型を格納する 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 クラスの新しいインスタンスを初期化し、指定した型のオブジェクトを、XmlDictionaryString のパラメーターを通して指定した XML ルート要素と名前空間を使用してシリアル化または逆シリアル化します。

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

rootNamespace
XmlDictionaryString

ルート要素の名前空間を含む XmlDictionaryString

次の例は、シリアル化または逆シリアル化する型と、XML ドキュメントに対して (DataContractSerializer オブジェクトとして) 読み取りまたは書き込みを行う XML 名と名前空間を指定する XmlDictionaryString のインスタンスを作成します。

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 クラスの新しいインスタンスを初期化し、指定した型のオブジェクトを、指定した 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 要素の名前空間。

次の例は、シリアル化または逆シリアル化する型と、XML ドキュメントに対して読み取りまたは書き込みを行う XML 名と名前空間を指定する DataContractSerializer のインスタンスを作成します。

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 クラスの新しいインスタンスを初期化します。

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 クラスの新しいインスタンスを初期化し、指定した型のオブジェクトと、オブジェクト グラフ内に存在可能な既知の型のコレクションをシリアル化または逆シリアル化します。

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>

オブジェクト グラフ内に存在可能な型を含む 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 クラスの新しいインスタンスを初期化し、指定した型のオブジェクトをシリアル化または逆シリアル化します。 このメソッドは、さらに、XML ルート要素と名前空間を示す 2 つの 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

rootNamespace
XmlDictionaryString

ルート要素の名前空間を含む XmlDictionaryString

knownTypes
IEnumerable<Type>

オブジェクト グラフ内に存在可能な既知の型を含む IEnumerable<T>Type

次の例は、シリアル化または逆シリアル化する型と、XML ドキュメントに対して (DataContractSerializer オブジェクトとして) 読み取りまたは書き込みを行う XML 名と名前空間を指定する XmlDictionaryString のインスタンスを作成します。 このコードはまた、シリアル化または逆シリアル化で使用される既知の型を格納する 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

こちらもご覧ください

適用対象