本文整理匯總了C#中System.Runtime.Remoting.ObjectHandle類的典型用法代碼示例。如果您正苦於以下問題:C# ObjectHandle類的具體用法?C# ObjectHandle怎麽用?C# ObjectHandle使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ObjectHandle類屬於System.Runtime.Remoting命名空間,在下文中一共展示了ObjectHandle類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MyType
//引入命名空間
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());
}
}