ObjectHandle.Unwrap Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne l'objet encapsulé.
public:
System::Object ^ Unwrap();
public:
virtual System::Object ^ Unwrap();
public object? Unwrap ();
public object Unwrap ();
member this.Unwrap : unit -> obj
abstract member Unwrap : unit -> obj
override this.Unwrap : unit -> obj
Public Function Unwrap () As Object
Retours
Objet encapsulé.
Implémente
Exemples
L’exemple de code suivant montre comment activer un objet dans un autre AppDomain, récupérer un proxy vers celui-ci avec la Unwrap méthode et utiliser le proxy pour accéder à l’objet distant.
// 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() );
// 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.
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())
Notes pour les appelants
Un ObjectHandle est un distant MarshalByRefObject suivi par le service de durée de vie de communication à distance. Un appel à la méthode actuelle peut échouer si le bail à durée de vie sur le ObjectHandle expire.