Freigeben über


ObjectHandle.Unwrap-Methode

Gibt das gewrappte Objekt zurück.

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

Syntax

'Declaration
Public Function Unwrap As Object
'Usage
Dim instance As ObjectHandle
Dim returnValue As Object

returnValue = instance.Unwrap
public Object Unwrap ()
public:
virtual Object^ Unwrap () sealed
public final Object Unwrap ()
public final function Unwrap () : Object

Rückgabewert

Das Objekt, für das ein Wrapper erstellt wird.

Hinweise

Hinweise für Aufrufer Ein ObjectHandle ist ein remote übertragenes MarshalByRefObject, das vom Remoting-Lebensdauerdienst verfolgt wird. Ein Aufruf der aktuellen Methode kann fehlschlagen, wenn der Lebensdauerlease für das ObjectHandle abläuft.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie ein Objekt in einer anderen AppDomain aktiviert wird und wie mit der Unwrap-Methode ein Proxy für dieses Objekt abgerufen und mit seiner Hilfe auf das Remoteobjekt zugegriffen wird.

' Creates an instance of MyType defined in the assembly called ObjectHandleAssembly.
Dim obj As ObjectHandle = domain.CreateInstance("ObjectHandleAssembly", "MyType")

' Unwrapps the proxy to the MyType object created in the other AppDomain.
Dim testObj As MyType = CType(obj.Unwrap(), MyType)

If RemotingServices.IsTransparentProxy(testObj) Then
   Console.WriteLine("The unwrapped object is a proxy.")
Else
   Console.WriteLine("The unwrapped object is not a proxy!")
End If 
Console.WriteLine("")
Console.Write("Calling a method on the object located in an AppDomain with the hash code ")
Console.WriteLine(testObj.GetAppDomainHashCode())
// Creates an instance of MyType defined in the assembly called ObjectHandleAssembly.
ObjectHandle obj = domain.CreateInstance("ObjectHandleAssembly", "MyType");

// Unwrapps the proxy to the MyType object created in the other AppDomain.
MyType testObj = (MyType)obj.Unwrap();

if(RemotingServices.IsTransparentProxy(testObj))
   Console.WriteLine("The unwrapped object is a proxy.");
else
   Console.WriteLine("The unwrapped object is not a proxy!");    

Console.WriteLine("");
Console.Write("Calling a method on the object located in an AppDomain with the hash code ");
Console.WriteLine(testObj.GetAppDomainHashCode());
// Creates an instance of MyType defined in the assembly called ObjectHandleAssembly.
ObjectHandle^ obj = domain->CreateInstance( "ObjectHandleAssembly", "MyType" );

// Unwraps the proxy to the MyType object created in the other AppDomain.
MyType^ testObj = dynamic_cast<MyType^>(obj->Unwrap());
if ( RemotingServices::IsTransparentProxy( testObj ) )
   Console::WriteLine( "The unwrapped object is a proxy." );
else
   Console::WriteLine( "The unwrapped object is not a proxy!" );

Console::WriteLine( "" );
Console::Write( "Calling a method on the object located in an AppDomain with the hash code " );
Console::WriteLine( testObj->GetAppDomainHashCode() );

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

ObjectHandle-Klasse
ObjectHandle-Member
System.Runtime.Remoting-Namespace