CodeTypeReference 類別

定義

表示型別的參考。

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

範例

下列範例示範如何使用 CodeTypeReference 來表示型別的參考。

// 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 物件的類型。 當 CodeDOM 類型具有 Type 屬性時,其類型為 CodeTypeReference 。 例如, CodeMemberField.Type 屬性是表示 CodeTypeReference 欄位資料類型的 。

CodeTypeReference可以使用 物件或字串初始化 Type 。 通常建議您使用 Type 來執行這項操作,但可能不一定可行。 如果使用字串初始化這個類別的實例,強烈建議一律使用完整類型,例如 「System.Console」,而不是只使用 「Console」,因為並非所有語言都支援匯入命名空間。 陣列類型可以藉由傳入陣列的類型物件,或使用接受排名做為參數的其中一個建構函式來指定。

屬性 BaseType 會指定要參考的類型名稱。 如需陣列類型的參考, ArrayElementType 屬性會指出陣列專案的型別,而 ArrayRank 屬性則表示陣列中的維度數目。

建構函式

CodeTypeReference()

初始化 CodeTypeReference 類別的新執行個體。

CodeTypeReference(CodeTypeParameter)

使用指定的程式碼型別參數,初始化 CodeTypeReference 類別的新執行個體。

CodeTypeReference(CodeTypeReference, Int32)

使用指定的陣列型別和陣序,初始化 CodeTypeReference 類別的新執行個體。

CodeTypeReference(String)

使用指定的型別名稱,初始化 CodeTypeReference 類別的新執行個體。

CodeTypeReference(String, CodeTypeReference[])

使用指定的型別名稱和型別引數,初始化 CodeTypeReference 類別的新執行個體。

CodeTypeReference(String, CodeTypeReferenceOptions)

使用指定的型別名稱和程式碼型別參考選項,初始化 CodeTypeReference 類別的新執行個體。

CodeTypeReference(String, Int32)

使用指定的陣列型別名稱和陣序,初始化 CodeTypeReference 類別的新執行個體。

CodeTypeReference(Type)

使用指定的型別,初始化 CodeTypeReference 類別的新執行個體。

CodeTypeReference(Type, CodeTypeReferenceOptions)

使用指定的型別和程式碼型別參考,初始化 CodeTypeReference 類別的新執行個體。

屬性

ArrayElementType

取得或設定陣列中的元素型別。

ArrayRank

取得或設定陣列的陣列陣序。

BaseType

取得或設定要參考的型別名稱。

Options

取得或設定程式碼型別參考選項。

TypeArguments

取得目前泛型型別參考的型別引數。

UserData

取得目前物件的使用者可定義資料。

(繼承來源 CodeObject)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於