Freigeben über


CodeTypeReference-Klasse

Stellt einen Verweis auf einen Typ dar.

Namespace: System.CodeDom
Assembly: System (in system.dll)

Syntax

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class CodeTypeReference
    Inherits CodeObject
'Usage
Dim instance As CodeTypeReference
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class CodeTypeReference : CodeObject
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class CodeTypeReference : public CodeObject
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class CodeTypeReference extends CodeObject
SerializableAttribute 
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class CodeTypeReference extends CodeObject

Hinweise

Ein CodeTypeReference-Objekt wird zum Darstellen eines Typs für CodeDOM-Objekte verwendet. Wenn CodeDOM-Typen über eine Type-Eigenschaft verfügen, ist diese vom Typ CodeTypeReference. Zum Beispiel ist die CodeMemberField.Type-Eigenschaft ein CodeTypeReference, der den Datentyp eines Felds darstellt.

Ein CodeTypeReference kann mit einem Type-Objekt oder einer Zeichenfolge initialisiert werden. Im Allgemeinen empfiehlt sich dabei die Verwendung von Type. Dies ist jedoch nicht immer möglich. Beim Initialisieren einer Instanz dieser Klasse mit einer Zeichenfolge wird dringend empfohlen, stets vollqualifizierte Typen zu verwenden (z. B. "System.Console" anstelle von "Console"), da das Importieren von Namespaces nicht von allen Sprachen unterstützt wird. Arraytypen können entweder durch Übergeben eines Typobjekts für ein Array angegeben werden oder durch Verwenden eines der Konstruktoren, die den Rang als Parameter akzeptieren.

Die BaseType-Eigenschaft gibt den Namen des Typs an, auf den verwiesen werden soll. Bei Verweisen auf Arraytypen gibt die ArrayElementType-Eigenschaft den Typ der Elemente des Arrays an, und die ArrayRank-Eigenschaft gibt die Anzahl der Dimensionen im Array an.

Beispiel

Im folgenden Beispiel wird veranschaulicht, wie mit CodeTypeReference ein Verweis auf einen Typ dargestellt wird.

' Creates a reference to the System.DateTime type.
Dim typeRef1 As New CodeTypeReference("System.DateTime")

' Creates a typeof expression for the specified type reference.
Dim typeof1 As New CodeTypeOfExpression(typeRef1)

' A Visual Basic code generator produces the following source code for the preceeding example code:    

'       GetType(System.DateTime)            
// Creates a reference to the System.DateTime type.
CodeTypeReference typeRef1 = new CodeTypeReference("System.DateTime");

// Creates a typeof expression for the specified type reference.
CodeTypeOfExpression typeof1 = new CodeTypeOfExpression(typeRef1);

// A C# code generator produces the following source code for the preceeding example code:    

//    typeof(System.DateTime);            
// Creates a reference to the System.DateTime type.
CodeTypeReference^ typeRef1 = gcnew CodeTypeReference( "System.DateTime" );

// Creates a typeof expression for the specified type reference.
CodeTypeOfExpression^ typeof1 = gcnew CodeTypeOfExpression( typeRef1 );

// A C# code generator produces the following source code for the preceeding example code:
//    typeof(System.DateTime);
// Creates a reference to the System.DateTime type.
CodeTypeReference typeRef1 = new CodeTypeReference("System.DateTime");
// Creates a typeof expression for the specified type reference.
CodeTypeOfExpression typeof1 = new CodeTypeOfExpression(typeRef1);
// A VJ# code generator produces the following source code for the 
// preceeding example code:    
//    System.DateTime.class.ToType();           

Vererbungshierarchie

System.Object
   System.CodeDom.CodeObject
    System.CodeDom.CodeTypeReference

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

CodeTypeReference-Member
System.CodeDom-Namespace