ObjectHandle Osztály

Definíció

A marshal-by-value objektumhivatkozások burkolása, amely lehetővé teszi, hogy közvetetten adják vissza őket.

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
Öröklődés
ObjectHandle
Attribútumok
Megvalósítás

Példák

Az alábbi példakód bemutatja, hogyan hozhat létre objektumot egy másikban AppDomain, és hogyan kérdezhet le proxyt az objektumhoz egy ObjectHandle. Ebben a példában feltételezheti, hogy az MyType osztály kódja egy "ObjectHandleAssembly" nevű szerelvénybe van lefordítva.

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

Megjegyzések

Az ObjectHandle osztály egy objektum (burkolt állapotban) átadására szolgál több alkalmazástartomány között anélkül, hogy betölti a becsomagolt objektum metaadatait minden olyan AppDomain helyen, amelyen áthalad ObjectHandle . Az osztály így szabályozza a hívó számára, ObjectHandle hogy mikor Type töltődik be a távoli objektum egy tartományba.

Konstruktorok

Name Description
ObjectHandle(Object)

Inicializálja az ObjectHandle osztály egy példányát, körbefuttatva az adott objektumot o.

Metódusok

Name Description
CreateObjRef(Type)

Létrehoz egy objektumot, amely tartalmazza a távoli objektumokkal való kommunikációhoz használt proxy létrehozásához szükséges összes releváns információt.

(Öröklődés forrása MarshalByRefObject)
Equals(Object)

Meghatározza, hogy a megadott objektum egyenlő-e az aktuális objektummal.

(Öröklődés forrása Object)
GetHashCode()

Ez az alapértelmezett kivonatoló függvény.

(Öröklődés forrása Object)
GetLifetimeService()
Elavult.

Lekéri a példány élettartamszabályzatát vezérlő aktuális élettartam-szolgáltatásobjektumot.

(Öröklődés forrása MarshalByRefObject)
GetType()

Lekéri az Type aktuális példányt.

(Öröklődés forrása Object)
InitializeLifetimeService()

Inicializálja a burkolt objektum élettartam-bérletét.

InitializeLifetimeService()
Elavult.

Beolvas egy élettartam-szolgáltatásobjektumot a példány élettartam-szabályzatának szabályozásához.

(Öröklődés forrása MarshalByRefObject)
MemberwiseClone()

Az aktuális Objectpéldány sekély másolatát hozza létre.

(Öröklődés forrása Object)
MemberwiseClone(Boolean)

Az aktuális MarshalByRefObject objektum sekély másolatát hozza létre.

(Öröklődés forrása MarshalByRefObject)
ToString()

Az aktuális objektumot jelképező sztringet ad vissza.

(Öröklődés forrása Object)
Unwrap()

A becsomagolt objektumot adja vissza.

A következőre érvényes: