ObjectHandle.Unwrap 方法  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回被包装的对象。
public:
 System::Object ^ Unwrap();public:
 virtual System::Object ^ Unwrap();public object? Unwrap ();public object Unwrap ();member this.Unwrap : unit -> objabstract member Unwrap : unit -> obj
override this.Unwrap : unit -> objPublic Function Unwrap () As 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())
调用方说明
是 ObjectHandle 远程处理生存期服务跟踪的远程 MarshalByRefObject 。 如果 的生存期租约过期,对当前方法的 ObjectHandle 调用可能会失败。