本文整理汇总了C#中System.Type.GetTypeHandle方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetTypeHandle方法的具体用法?C# Type.GetTypeHandle怎么用?C# Type.GetTypeHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.GetTypeHandle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MyMethod
//引入命名空间
using System;
using System.Reflection;
public class MyClass1
{
private int x=0;
public int MyMethod()
{
return x;
}
}
public class MyClass2
{
public static void Main()
{
MyClass1 myClass1 = new MyClass1();
// Get the RuntimeTypeHandle from an object.
RuntimeTypeHandle myRTHFromObject = Type.GetTypeHandle(myClass1);
// Get the RuntimeTypeHandle from a type.
RuntimeTypeHandle myRTHFromType = typeof(MyClass1).TypeHandle;
Console.WriteLine("\nmyRTHFromObject.Value: {0}", myRTHFromObject.Value);
Console.WriteLine("myRTHFromObject.GetType(): {0}", myRTHFromObject.GetType());
Console.WriteLine("Get the type back from the handle...");
Console.WriteLine("Type.GetTypeFromHandle(myRTHFromObject): {0}",
Type.GetTypeFromHandle(myRTHFromObject));
Console.WriteLine("\nmyRTHFromObject.Equals(myRTHFromType): {0}",
myRTHFromObject.Equals(myRTHFromType));
Console.WriteLine("\nmyRTHFromType.Value: {0}", myRTHFromType.Value);
Console.WriteLine("myRTHFromType.GetType(): {0}", myRTHFromType.GetType());
Console.WriteLine("Get the type back from the handle...");
Console.WriteLine("Type.GetTypeFromHandle(myRTHFromType): {0}",
Type.GetTypeFromHandle(myRTHFromType));
}
}
输出:
myRTHFromObject.Value: 799464 myRTHFromObject.GetType(): System.RuntimeTypeHandle Get the type back from the handle... Type.GetTypeFromHandle(myRTHFromObject): MyClass1 myRTHFromObject.Equals(myRTHFromType): True myRTHFromType.Value: 799464 myRTHFromType.GetType(): System.RuntimeTypeHandle Get the type back from the handle... Type.GetTypeFromHandle(myRTHFromType): MyClass1