CodeTypeOfExpression 類別

定義

表示 typeof 運算式,它會傳回指定型別名稱的 Type

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

範例

下列範例示範如何使用 CodeTypeOfExpression 來表示 typeof 運算式。

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

備註

CodeTypeOfExpression表示在typeof運行時間傳回 的Type表達式。

屬性 Type 會指定要傳回 Type 物件的數據類型。

使用 CodeTypeReferenceExpression 來表示依名稱參照類型的原始程式碼,例如在建立 CodeCastExpression 以將物件轉換成名稱指定的型別時。

建構函式

CodeTypeOfExpression()

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

CodeTypeOfExpression(CodeTypeReference)

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

CodeTypeOfExpression(String)

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

CodeTypeOfExpression(Type)

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

屬性

Type

取得或設定 typeof 運算式所參考的資料型別。

UserData

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

(繼承來源 CodeObject)

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

適用於

另請參閱