ObjectHandle.Unwrap ObjectHandle.Unwrap ObjectHandle.Unwrap ObjectHandle.Unwrap Method

定義

ラップされたオブジェクトを返します。Returns the wrapped object.

public:
 virtual System::Object ^ Unwrap();
public object Unwrap ();
abstract member Unwrap : unit -> obj
override this.Unwrap : unit -> obj
Public Function Unwrap () As Object

戻り値

ラップされたオブジェクト。The wrapped object.

実装

次のコード例は、別のオブジェクトをアクティブ化する方法を示しますAppDomainを使ってプロキシを取得、Unwrapメソッド、およびリモート オブジェクトへのアクセスにプロキシを使用します。The following code example demonstrates how to activate an object in another AppDomain, retrieve a proxy to it with the Unwrap method, and use the proxy to access the remote object.

// 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())

注意 (呼び出し元)

AObjectHandleが、リモート処理MarshalByRefObjectはリモート処理有効期間サービスによって追跡されます。A ObjectHandle is a remoted MarshalByRefObject that is tracked by the remoting lifetime service. 有効期間のリースの場合、現在のメソッドの呼び出しは失敗、ObjectHandle有効期限が切れます。A call to the current method can fail if the lifetime lease on the ObjectHandle expires.

適用対象