ObjectHandle 클래스

정의

값으로 마샬링된 개체 참조를 래핑하여 간접 참조를 통해 반환할 수 있도록 합니다.

public ref class ObjectHandle : MarshalByRefObject
public ref class ObjectHandle : MarshalByRefObject, System::Runtime::Remoting::IObjectHandle
public class ObjectHandle : MarshalByRefObject
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDual)]
public class ObjectHandle : MarshalByRefObject, System.Runtime.Remoting.IObjectHandle
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDual)]
[System.Runtime.InteropServices.ComVisible(true)]
public class ObjectHandle : MarshalByRefObject, System.Runtime.Remoting.IObjectHandle
type ObjectHandle = class
    inherit MarshalByRefObject
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDual)>]
type ObjectHandle = class
    inherit MarshalByRefObject
    interface IObjectHandle
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDual)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ObjectHandle = class
    inherit MarshalByRefObject
    interface IObjectHandle
Public Class ObjectHandle
Inherits MarshalByRefObject
Public Class ObjectHandle
Inherits MarshalByRefObject
Implements IObjectHandle
상속
ObjectHandle
특성
구현

예제

다음 코드 예제에서는 다른 AppDomain개체에서 개체를 만들고 개체에 대한 프록시를 검색하는 ObjectHandle방법을 보여줍니다. 이 예제에서는 클래스의 MyType 코드가 "ObjectHandleAssembly"라는 어셈블리로 컴파일된다고 가정할 수 있습니다.

using namespace System;
using namespace System::Runtime::Remoting;
public ref class MyType: public MarshalByRefObject
{
public:
   MyType()
   {
      Console::Write( "Created an instance of MyType in an AppDomain with the " );
      Console::WriteLine( "hash code {0}", AppDomain::CurrentDomain->GetHashCode() );
      Console::WriteLine( "" );
   }

   int GetAppDomainHashCode()
   {
      return AppDomain::CurrentDomain->GetHashCode();
   }

};

int main()
{
   Console::WriteLine( "The hash code of the default AppDomain is {0}.", AppDomain::CurrentDomain->GetHashCode() );
   Console::WriteLine( "" );
   
   // Creates another AppDomain.
   AppDomain^ domain = AppDomain::CreateDomain( "AnotherDomain", nullptr, (AppDomainSetup^)nullptr );
   
   // 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() );
   
}
using System;
using System.Runtime.Remoting;

public class MyType : MarshalByRefObject {

   public MyType()  {
      Console.Write("Created an instance of MyType in an AppDomain with the ");
      Console.WriteLine("hash code {0}",AppDomain.CurrentDomain.GetHashCode());
      Console.WriteLine("");
   }

   public int GetAppDomainHashCode() {
      return AppDomain.CurrentDomain.GetHashCode();
   }
}

class Test {

   public static void Main() {

      Console.WriteLine("The hash code of the default AppDomain is {0}.",
                        AppDomain.CurrentDomain.GetHashCode());
      Console.WriteLine("");

      // Creates another AppDomain.
      AppDomain domain = AppDomain.CreateDomain("AnotherDomain",
                                                null,
                                                (AppDomainSetup)null);

      // 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());
   }
}
Imports System.Runtime.Remoting


Public Class MyType
   Inherits MarshalByRefObject
      
   Public Sub New()
      Console.Write("Created an instance of MyType in an AppDomain with the ")
      Console.WriteLine("hashcode {0}", AppDomain.CurrentDomain.GetHashCode())
      Console.WriteLine("")
   End Sub
   
   
   Public Function GetAppDomainHashCode() As Integer
      Return AppDomain.CurrentDomain.GetHashCode()
   End Function 'GetAppDomainHashCode

End Class


Class Test
     
   Public Shared Sub Main()
      
      Console.WriteLine("The hash code of the default AppDomain is {0}.", AppDomain.CurrentDomain.GetHashCode())
      Console.WriteLine("")
      
      ' Creates another AppDomain.
      Dim domain As AppDomain = AppDomain.CreateDomain("AnotherDomain", Nothing, CType(Nothing, AppDomainSetup))
      
      ' 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())

   End Sub

End Class

설명

합니다 ObjectHandle 클래스는 래핑된 개체 각각에 대 한 메타 데이터를 로드 하지 않고 여러 애플리케이션 도메인 간에 개체 (래핑된)을 전달 하는 데 사용 됩니다 AppDomainObjectHandle 이동 합니다. 따라서 클래스는 ObjectHandle 원격 개체가 도메인에 로드되는 시기를 Type 호출자에게 제어합니다.

생성자

ObjectHandle(Object)

ObjectHandle 클래스의 인스턴스를 초기화하고 제공된 개체 o를 래핑합니다.

메서드

CreateObjRef(Type)

원격 개체와 통신하는 데 사용되는 프록시 생성에 필요한 모든 관련 정보가 들어 있는 개체를 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetLifetimeService()
사용되지 않습니다.

이 인스턴스의 수명 정책을 제어하는 현재의 수명 서비스 개체를 검색합니다.

(다음에서 상속됨 MarshalByRefObject)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
InitializeLifetimeService()

래핑된 개체의 수명 임대를 초기화합니다.

InitializeLifetimeService()
사용되지 않습니다.

이 인스턴스의 수명 정책을 제어하는 수명 서비스 개체를 가져옵니다.

(다음에서 상속됨 MarshalByRefObject)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
MemberwiseClone(Boolean)

현재 MarshalByRefObject 개체의 단순 복사본을 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
Unwrap()

래핑된 개체를 반환합니다.

적용 대상