ObjectHandle クラス
アセンブリ: 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

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.MarshalByRefObject
System.Runtime.Remoting.ObjectHandle


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ObjectHandle コンストラクタ
アセンブリ: mscorlib (mscorlib.dll 内)


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ObjectHandle メソッド

名前 | 説明 | |
---|---|---|
![]() | CreateObjRef | リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。 ( MarshalByRefObject から継承されます。) |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetLifetimeService | 対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。 ( MarshalByRefObject から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | InitializeLifetimeService | オーバーライドされます。 ラップされたオブジェクトの有効期間リースを初期化します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
![]() | Unwrap | ラップされたオブジェクトを返します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |

ObjectHandle メンバ
値渡しでマーシャリングされるオブジェクト参照をラップし、それらの参照が間接参照を通じて返されるようにします。
ObjectHandle データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | CreateObjRef | リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。 (MarshalByRefObject から継承されます。) |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetLifetimeService | 対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。 (MarshalByRefObject から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | InitializeLifetimeService | オーバーライドされます。 ラップされたオブジェクトの有効期間リースを初期化します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
![]() | Unwrap | ラップされたオブジェクトを返します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |

- ObjectHandleのページへのリンク