CodeTypeReference CodeTypeReference CodeTypeReference CodeTypeReference Class

定義

表示型別的參考。Represents a reference to a type.

public ref class CodeTypeReference : System::CodeDom::CodeObject
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeTypeReference : System.CodeDom.CodeObject
type CodeTypeReference = class
    inherit CodeObject
Public Class CodeTypeReference
Inherits CodeObject
繼承
CodeTypeReferenceCodeTypeReferenceCodeTypeReferenceCodeTypeReference
屬性

範例

下列範例示範如何使用CodeTypeReference來代表類型的參考。The following example demonstrates use of a CodeTypeReference to represent a reference to a type.

// 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);

// Create a C# code provider
CodeDomProvider^ provider = CodeDomProvider::CreateProvider("CSharp");

// Generate code and send the output to the console
provider->GenerateCodeFromExpression(typeof1, Console::Out, gcnew CodeGeneratorOptions());
// The 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);

// Create a C# code provider
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");

// Generate code and send the output to the console
provider.GenerateCodeFromExpression(typeof1, Console.Out, new CodeGeneratorOptions());
// The code generator produces the following source code for the preceeding example code:
//    typeof(System.DateTime)
' 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)

' Create a Visual Basic code provider
Dim provider As CodeDomProvider = CodeDomProvider.CreateProvider("VisualBasic")

' Generate code and send the output to the console
provider.GenerateCodeFromExpression(typeof1, Console.Out, new CodeGeneratorOptions())
' The code generator produces the following source code for the preceeding example code:
'    GetType(Date)

備註

CodeTypeReference物件是用來表示 CodeDOM 物件的型別。A CodeTypeReference object is used to represent a type for CodeDOM objects. 當 CodeDOM 類型具有Type屬性時, 其類型CodeTypeReference為。When CodeDOM types have a Type property, it is of type CodeTypeReference. 例如, CodeMemberField.Type屬性CodeTypeReference是, 代表欄位的資料類型。For example, the CodeMemberField.Type property is a CodeTypeReference that represents a field's data type.

CodeTypeReference 可以Type使用物件或字串來初始化。A CodeTypeReference can be initialized with a Type object or a string. 通常建議使用Type來執行此動作, 但可能不一定可行。It is generally recommended to use a Type to do this, although it may not always be possible. 如果使用字串初始化此類別的實例, 則強烈建議一律使用完整類型, 例如 "System. Console", 而不只是 "Console", 因為並非所有語言都支援匯入命名空間。If initializing an instance of this class with a string, it is strongly recommended to always use fully qualified types, such as "System.Console" instead of just "Console", because not all languages support importing namespaces. 陣列類型可以藉由傳入陣列的類型物件, 或使用接受 rank 做為參數的其中一個函式來指定。Array types can be specified by either passing in a type object for an array or using one of the constructors that accept rank as a parameter.

BaseType屬性會指定要參考之類型的名稱。The BaseType property specifies the name of the type to reference. 針對陣列類型的參考, ArrayElementType屬性會指出陣列元素的類型, ArrayRank而屬性會指出陣列中的維度數目。For references to array types, the ArrayElementType property indicates the type of the elements of the array, and the ArrayRank property indicates the number of dimensions in the array.

建構函式

CodeTypeReference() CodeTypeReference() CodeTypeReference() CodeTypeReference()

初始化 CodeTypeReference 類別的新執行個體。Initializes a new instance of the CodeTypeReference class.

CodeTypeReference(CodeTypeParameter) CodeTypeReference(CodeTypeParameter) CodeTypeReference(CodeTypeParameter) CodeTypeReference(CodeTypeParameter)

使用指定的程式碼型別參數,初始化 CodeTypeReference 類別的新執行個體。Initializes a new instance of the CodeTypeReference class using the specified code type parameter.

CodeTypeReference(CodeTypeReference, Int32) CodeTypeReference(CodeTypeReference, Int32) CodeTypeReference(CodeTypeReference, Int32) CodeTypeReference(CodeTypeReference, Int32)

使用指定的陣列型別和陣序,初始化 CodeTypeReference 類別的新執行個體。Initializes a new instance of the CodeTypeReference class using the specified array type and rank.

CodeTypeReference(String) CodeTypeReference(String) CodeTypeReference(String) CodeTypeReference(String)

使用指定的型別名稱,初始化 CodeTypeReference 類別的新執行個體。Initializes a new instance of the CodeTypeReference class using the specified type name.

CodeTypeReference(String, CodeTypeReferenceOptions) CodeTypeReference(String, CodeTypeReferenceOptions) CodeTypeReference(String, CodeTypeReferenceOptions) CodeTypeReference(String, CodeTypeReferenceOptions)

使用指定的型別名稱和程式碼型別參考選項,初始化 CodeTypeReference 類別的新執行個體。Initializes a new instance of the CodeTypeReference class using the specified type name and code type reference option.

CodeTypeReference(String, CodeTypeReference[]) CodeTypeReference(String, CodeTypeReference[]) CodeTypeReference(String, CodeTypeReference[]) CodeTypeReference(String, CodeTypeReference[])

使用指定的型別名稱和型別引數,初始化 CodeTypeReference 類別的新執行個體。Initializes a new instance of the CodeTypeReference class using the specified type name and type arguments.

CodeTypeReference(String, Int32) CodeTypeReference(String, Int32) CodeTypeReference(String, Int32) CodeTypeReference(String, Int32)

使用指定的陣列型別名稱和陣序,初始化 CodeTypeReference 類別的新執行個體。Initializes a new instance of the CodeTypeReference class using the specified array type name and rank.

CodeTypeReference(Type) CodeTypeReference(Type) CodeTypeReference(Type) CodeTypeReference(Type)

使用指定的型別,初始化 CodeTypeReference 類別的新執行個體。Initializes a new instance of the CodeTypeReference class using the specified type.

CodeTypeReference(Type, CodeTypeReferenceOptions) CodeTypeReference(Type, CodeTypeReferenceOptions) CodeTypeReference(Type, CodeTypeReferenceOptions) CodeTypeReference(Type, CodeTypeReferenceOptions)

使用指定的型別和程式碼型別參考,初始化 CodeTypeReference 類別的新執行個體。Initializes a new instance of the CodeTypeReference class using the specified type and code type reference.

屬性

ArrayElementType ArrayElementType ArrayElementType ArrayElementType

取得或設定陣列中的元素型別。Gets or sets the type of the elements in the array.

ArrayRank ArrayRank ArrayRank ArrayRank

取得或設定陣列的陣列陣序。Gets or sets the array rank of the array.

BaseType BaseType BaseType BaseType

取得或設定要參考的型別名稱。Gets or sets the name of the type being referenced.

Options Options Options Options

取得或設定程式碼型別參考選項。Gets or sets the code type reference option.

TypeArguments TypeArguments TypeArguments TypeArguments

取得目前泛型型別參考的型別引數。Gets the type arguments for the current generic type reference.

UserData UserData UserData UserData

取得目前物件的使用者可定義資料。Gets the user-definable data for the current object.

(Inherited from CodeObject)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於