ObjectHandle.Unwrap メソッド

定義

ラップされたオブジェクトを返します。

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

戻り値

Object

ラップされたオブジェクト。

実装

次のコード例は、別 AppDomainのオブジェクトをアクティブ化し、メソッドを使用 Unwrap してプロキシを取得し、プロキシを使用してリモート オブジェクトにアクセスする方法を示しています。

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

注意 (呼び出し元)

A ObjectHandle はリモート処理の有効期間サービスによって追跡されるリモート MarshalByRefObject です。 現在のメソッドの呼び出しは、有効期限が切れた場合に ObjectHandle 失敗する可能性があります。

適用対象