ObjectHandle クラスとは? わかりやすく解説

ObjectHandle クラス

値渡しマーシャリングされるオブジェクト参照ラップし、それらの参照間接参照通じて返されるようにします。

名前空間: System.Runtime.Remoting
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDual)> _
Public Class ObjectHandle
    Inherits MarshalByRefObject
    Implements IObjectHandle
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDual)] 
public class ObjectHandle : MarshalByRefObject,
 IObjectHandle
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDual)] 
public ref class ObjectHandle : public
 MarshalByRefObject, IObjectHandle
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDual) */ 
public class ObjectHandle extends MarshalByRefObject
 implements IObjectHandle
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDual) 
public class ObjectHandle extends
 MarshalByRefObject implements IObjectHandle
解説解説

ObjectHandle クラスは、ラップされた状態のオブジェクト複数アプリケーション ドメイン間で渡すために使用され、このとき、ラップされているオブジェクトメタデータをその ObjectHandle がたどる各 AppDomain読み込む要はありません。したがってObjectHandle クラス使用すると、リモート オブジェクトTypeドメインにいつ読み込むかを呼び出し元が制御できるようになります

使用例使用例

別の AppDomain 内でオブジェクト作成してObjectHandle からこのオブジェクトへのプロキシ取得する方法を、次のコード例示します。この例では、MyType クラスコードが "ObjectHandleAssembly" というアセンブリコンパイル済みであることを前提としています。

Imports System
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 'New
   
   
   Public Function GetAppDomainHashCode() As
 Integer
      Return AppDomain.CurrentDomain.GetHashCode()
   End Function 'GetAppDomainHashCode

End Class 'MyType


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 'Main 

End Class 'Test 
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());
   }
}
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() );
   
}

継承階層継承階層
System.Object
   System.MarshalByRefObject
    System.Runtime.Remoting.ObjectHandle
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ObjectHandle メンバ
System.Runtime.Remoting 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ObjectHandle クラス」の関連用語

ObjectHandle クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ObjectHandle クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS