public class ObjectHandle : MarshalByRefObject, IObjectHandle
|
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());
}
}
| ctor #1 | Initializes an instance of the ObjectHandle class, wrapping the given object o. |
| CreateObjRef (inherited from System.MarshalByRefObject) |
See base class member description: System.MarshalByRefObject.CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. |
| Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
| GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
| GetLifetimeService (inherited from System.MarshalByRefObject) |
See base class member description: System.MarshalByRefObject.GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. |
| GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
| InitializeLifetimeService | Overridden: Initializes the lifetime lease of the wrapped object. |
| ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
| Unwrap | Returns the wrapped object. |
| Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
| MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public ObjectHandle( |
o
requestedType
| Exception Type | Condition |
|---|---|
| RemotingException | This instance is not a valid remoting object. |
~ObjectHandle(); |
public virtual int GetHashCode(); |
public object GetLifetimeService(); |
public Type GetType(); |
public override object InitializeLifetimeService(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |
public object Unwrap(); |
// 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());