ObjectHandle Klas
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Verpakt marshal-by-value objectverwijzingen, zodat ze kunnen worden geretourneerd via een indirectie.
public ref class ObjectHandle : MarshalByRefObject, System::Runtime::Remoting::IObjectHandle
[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
[<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
Implements IObjectHandle
- Overname
- Kenmerken
- Implementeringen
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u een object in een ander AppDomainobject maakt en een proxy ophaalt naar het object van een ObjectHandle. In dit voorbeeld kunt u ervan uitgaan dat de code van de MyType klasse is gecompileerd in een assembly met de naam 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
Opmerkingen
De ObjectHandle klasse wordt gebruikt om een object (in een verpakte status) door te geven tussen meerdere toepassingsdomeinen zonder dat de metagegevens voor het verpakte object worden geladen in elk AppDomain object waarin de ObjectHandle verplaatsing plaatsvindt. ObjectHandle De klasse geeft de aanroeper dus controle over wanneer het Type externe object in een domein wordt geladen.
Constructors
| Name | Description |
|---|---|
| ObjectHandle(Object) |
Initialiseert een exemplaar van de ObjectHandle klasse en verpakt het opgegeven object |
Methoden
| Name | Description |
|---|---|
| CreateObjRef(Type) |
Hiermee maakt u een object dat alle relevante informatie bevat die nodig is om een proxy te genereren die wordt gebruikt om te communiceren met een extern object. (Overgenomen van MarshalByRefObject) |
| Equals(Object) |
Bepaalt of het opgegeven object gelijk is aan het huidige object. (Overgenomen van Object) |
| GetHashCode() |
Fungeert als de standaardhashfunctie. (Overgenomen van Object) |
| GetLifetimeService() |
Hiermee haalt u het huidige levensduurserviceobject op waarmee het levensduurbeleid voor dit exemplaar wordt beheerd. (Overgenomen van MarshalByRefObject) |
| GetType() |
Hiermee haalt u de Type huidige instantie op. (Overgenomen van Object) |
| InitializeLifetimeService() |
Initialiseert de levensduur van het verpakte object. |
| MemberwiseClone() |
Hiermee maakt u een ondiepe kopie van de huidige Object. (Overgenomen van Object) |
| MemberwiseClone(Boolean) |
Hiermee maakt u een ondiepe kopie van het huidige MarshalByRefObject object. (Overgenomen van MarshalByRefObject) |
| ToString() |
Retourneert een tekenreeks die het huidige object vertegenwoordigt. (Overgenomen van Object) |
| Unwrap() |
Retourneert het verpakte object. |