Type.TypeHandle Özellik
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.
Geçerli Typetanıtıcısını alır.
public:
virtual property RuntimeTypeHandle TypeHandle { RuntimeTypeHandle get(); };
public:
abstract property RuntimeTypeHandle TypeHandle { RuntimeTypeHandle get(); };
public virtual RuntimeTypeHandle TypeHandle { get; }
public abstract RuntimeTypeHandle TypeHandle { get; }
member this.TypeHandle : RuntimeTypeHandle
Public Overridable ReadOnly Property TypeHandle As RuntimeTypeHandle
Public MustOverride ReadOnly Property TypeHandle As RuntimeTypeHandle
Özellik Değeri
Geçerli Typeiçin tanıtıcı.
Uygulamalar
Özel durumlar
.NET Compact Framework şu anda bu özelliği desteklemiyor.
Örnekler
Aşağıdaki örnek, karşılık gelen türün tutamacını döndürür ve tanıtıcıyı, türü tanıtıcıdan alan ve görüntüleyen bir yönteme geçirir.
using System;
using System.Reflection;
class MyClass
{
public int myField = 10;
}
class Type_TypeHandle
{
public static void Main()
{
try
{
MyClass myClass = new MyClass();
// Get the type of MyClass.
Type myClassType = myClass.GetType();
// Get the runtime handle of MyClass.
RuntimeTypeHandle myClassHandle = myClassType.TypeHandle;
DisplayTypeHandle(myClassHandle);
}
catch(Exception e)
{
Console.WriteLine("Exception: {0}", e.Message );
}
}
public static void DisplayTypeHandle(RuntimeTypeHandle myTypeHandle)
{
// Get the type from the handle.
Type myType = Type.GetTypeFromHandle(myTypeHandle);
// Display the type.
Console.WriteLine("\nDisplaying the type from the handle:\n");
Console.WriteLine("The type is {0}.", myType.ToString());
}
}
open System
type MyClass() =
let myField = 10
let displayTypeHandle (myTypeHandle: RuntimeTypeHandle) =
// Get the type from the handle.
let myType = Type.GetTypeFromHandle myTypeHandle
// Display the type.
printfn $"\nDisplaying the type from the handle:\n"
printfn $"The type is {myType}."
let myClass = MyClass()
// Get the type of MyClass.
let myClassType = myClass.GetType()
// Get the runtime handle of MyClass.
let myClassHandle = myClassType.TypeHandle
displayTypeHandle myClassHandle
Imports System.Reflection
Class [MyClass]
Public myField As Integer = 10
End Class
Class Type_TypeHandle
Public Shared Sub Main()
Try
Dim [myClass] As New [MyClass]()
' Get the type of MyClass.
Dim myClassType As Type = [myClass].GetType()
' Get the runtime handle of MyClass.
Dim myClassHandle As RuntimeTypeHandle = myClassType.TypeHandle
DisplayTypeHandle(myClassHandle)
Catch e As Exception
Console.WriteLine("Exception: {0}", e.Message.ToString())
End Try
End Sub
Public Shared Sub DisplayTypeHandle(ByVal myTypeHandle As RuntimeTypeHandle)
' Get the type from the handle.
Dim myType As Type = Type.GetTypeFromHandle(myTypeHandle)
' Display the type.
Console.WriteLine(ControlChars.NewLine + "Displaying the type from the handle:" + ControlChars.NewLine)
Console.WriteLine("The type is {0}.", myType.ToString())
End Sub
End Class
Açıklamalar
TypeHandle türü temsil eden bir iç veri yapısının işaretçisini kapsüller. Bu tanıtıcı, işlem ömrü boyunca benzersizdir. Tanıtıcı yalnızca alındığı uygulama etki alanında geçerlidir.