CodeTypeOfExpression CodeTypeOfExpression CodeTypeOfExpression CodeTypeOfExpression Class

定義

表示 typeof 運算式,它會傳回指定型別名稱的 TypeRepresents a typeof expression, an expression that returns a Type for a specified type name.

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

範例

下列範例示範CodeTypeOfExpression如何使用來代表 typeof 運算式。The following example demonstrates use of a CodeTypeOfExpression to represent a typeof expression.

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

備註

表示在執行時間傳回的Type 運算式。typeof CodeTypeOfExpressionA CodeTypeOfExpression represents a typeof expression that returns a Type at runtime.

屬性會指定要Type為其傳回物件的資料類型。 TypeThe Type property specifies the data type to return a Type object for.

CodeTypeReferenceExpression來代表依名稱參考類型的原始程式碼, 例如CodeCastExpression建立時, 將物件轉換成名稱指定的類型。Use CodeTypeReferenceExpression to represent source code that refers to a type by name, such as when creating a CodeCastExpression to cast an object to a name-specified type.

建構函式

CodeTypeOfExpression() CodeTypeOfExpression() CodeTypeOfExpression() CodeTypeOfExpression()

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

CodeTypeOfExpression(CodeTypeReference) CodeTypeOfExpression(CodeTypeReference) CodeTypeOfExpression(CodeTypeReference) CodeTypeOfExpression(CodeTypeReference)

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

CodeTypeOfExpression(String) CodeTypeOfExpression(String) CodeTypeOfExpression(String) CodeTypeOfExpression(String)

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

CodeTypeOfExpression(Type) CodeTypeOfExpression(Type) CodeTypeOfExpression(Type) CodeTypeOfExpression(Type)

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

屬性

Type Type Type Type

取得或設定 typeof 運算式所參考的資料型別。Gets or sets the data type referenced by the typeof expression.

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)

適用於

另請參閱