ObjectHandle Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Değere göre hazırlama nesnesi başvurularını sarmalar ve bunların bir dolaylı yoldan döndürülmelerini sağlar.
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
- Devralma
- Öznitelikler
- Uygulamalar
Örnekler
Aşağıdaki kod örneğinde başka AppDomainbir içinde nesne oluşturma ve nesnesine ObjectHandlebir proxy alma işlemi gösterilmektedir. Bu örnekte, sınıfının kodunun MyType "ObjectHandleAssembly" adlı bir derlemede derlendiğini varsayabilirsiniz.
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
Açıklamalar
ObjectHandle sınıfı, her birinde gezindiği ObjectHandle sarmalanmış nesnenin meta verilerini yüklemeden birden çok uygulama etki alanı arasında bir nesne AppDomain (sarmalanmış durumda) geçirmek için kullanılır. Bu nedenle, sınıfı, ObjectHandle uzak nesnenin bir etki alanına ne zaman Type yüklendiğini çağıran denetimi verir.
Oluşturucular
| Name | Description |
|---|---|
| ObjectHandle(Object) |
Sınıfının bir örneğini ObjectHandle başlatır ve verilen nesnesini |
Yöntemler
| Name | Description |
|---|---|
| CreateObjRef(Type) |
Uzak bir nesneyle iletişim kurmak için kullanılan bir ara sunucu oluşturmak için gereken tüm ilgili bilgileri içeren bir nesne oluşturur. (Devralındığı yer: MarshalByRefObject) |
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
| GetHashCode() |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
| GetLifetimeService() |
Bu örnek için yaşam süresi ilkesini denetleen geçerli yaşam süresi hizmet nesnesini alır. (Devralındığı yer: MarshalByRefObject) |
| GetType() |
Geçerli örneğin Type alır. (Devralındığı yer: Object) |
| InitializeLifetimeService() |
Sarmalanan nesnenin yaşam süresi kirasını başlatır. |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| MemberwiseClone(Boolean) |
Geçerli MarshalByRefObject nesnenin sığ bir kopyasını oluşturur. (Devralındığı yer: MarshalByRefObject) |
| ToString() |
Geçerli nesneyi temsil eden bir dize döndürür. (Devralındığı yer: Object) |
| Unwrap() |
Sarmalanan nesneyi döndürür. |