SurrogateSelector.AddSurrogate-Methode

Fügt der Liste der überprüften Ersatzelemente ein Ersatzelement hinzu.

Namespace: System.Runtime.Serialization
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overridable Sub AddSurrogate ( _
    type As Type, _
    context As StreamingContext, _
    surrogate As ISerializationSurrogate _
)
'Usage
Dim instance As SurrogateSelector
Dim type As Type
Dim context As StreamingContext
Dim surrogate As ISerializationSurrogate

instance.AddSurrogate(type, context, surrogate)
public virtual void AddSurrogate (
    Type type,
    StreamingContext context,
    ISerializationSurrogate surrogate
)
public:
virtual void AddSurrogate (
    Type^ type, 
    StreamingContext context, 
    ISerializationSurrogate^ surrogate
)
public void AddSurrogate (
    Type type, 
    StreamingContext context, 
    ISerializationSurrogate surrogate
)
public function AddSurrogate (
    type : Type, 
    context : StreamingContext, 
    surrogate : ISerializationSurrogate
)

Parameter

  • type
    Der Type, für den ein Ersatz erforderlich ist.
  • context
    Die kontextspezifischen Daten.
  • surrogate
    Der für diesen Typ aufzurufende Ersatz.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentNullException

Der type-Parameter oder der surrogate-Parameter ist NULL (Nothing in Visual Basic).

ArgumentException

Für diesen Typ und Kontext ist bereits ein Ersatz vorhanden.

Beispiel

Im folgenden Codebeispiel wird das Aufrufen der AddSurrogate-Methode veranschaulicht. Dieses Codebeispiel ist Teil eines umfangreicheren Beispiels für die SurrogateSelector-Klasse.

// Create a SurrogateSelector.
SurrogateSelector ss = new SurrogateSelector();

// Tell the SurrogateSelector that Employee objects are serialized and deserialized 
// using the EmployeeSerializationSurrogate object.
ss.AddSurrogate(typeof(Employee),
new StreamingContext(StreamingContextStates.All),
new EmployeeSerializationSurrogate());

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

SurrogateSelector-Klasse
SurrogateSelector-Member
System.Runtime.Serialization-Namespace