本文整理汇总了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());
}
}