Biblioteca de clases de .NET Framework
ObjectHandle.Unwrap (Método)

Devuelve el objeto ajustado.

Espacio de nombres: System.Runtime.Remoting
Ensamblado: mscorlib (en mscorlib.dll)

Sintaxis

Visual Basic (Declaración)
Public Function Unwrap As Object
Visual Basic (Uso)
Dim instance As ObjectHandle
Dim returnValue As Object

returnValue = instance.Unwrap
C#
public Object Unwrap ()
C++
public:
virtual Object^ Unwrap () sealed
J#
public final Object Unwrap ()
JScript
public final function Unwrap () : Object

Valor devuelto

El objeto ajustado.
Comentarios

Notas para los llamadores Un ObjectHandle es un MarshalByRefObject remoto cuyo seguimiento se realiza mediante el servicio de duración remoto. Una llamada al método actual puede fallar si vence el período de duración de ObjectHandle.

Ejemplo

En el siguiente ejemplo de código se muestra cómo activar un objeto en otro AppDomain, recuperar el proxy con el método Unwrap y utilizar el proxy para tener acceso al objeto remoto.

Visual Basic
' 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())
C#
// 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());
C++
// 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() );
Plataformas

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

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

Información de versión

.NET Framework

Compatible con: 2.0, 1.1, 1.0
Vea también

Etiquetas :


Page view tracker