ObjectHandle.Unwrap 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回被包裝的物件。
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
傳回
被包裝的物件。
實作
範例
下列程式代碼範例示範如何啟動另一個 AppDomain中的物件、使用 Unwrap 方法擷取 Proxy,並使用 Proxy 來存取遠端物件。
// 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())
給呼叫者的注意事項
ObjectHandle是遠端服務所追蹤的遠端MarshalByRefObject。 如果的存留期租用到期,對目前方法的 ObjectHandle 呼叫可能會失敗。