CodeTypeOfExpression 类

定义

表示 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
继承
CodeTypeOfExpression
属性

示例

下面的示例演示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 类的新实例。Initializes a new instance of the CodeTypeOfExpression class.

CodeTypeOfExpression(CodeTypeReference)

初始化 CodeTypeOfExpression 类的新实例。Initializes a new instance of the CodeTypeOfExpression class.

CodeTypeOfExpression(String)

使用指定的类型初始化 CodeTypeOfExpression 类的新实例。Initializes a new instance of the CodeTypeOfExpression class using the specified type.

CodeTypeOfExpression(Type)

使用指定的类型初始化 CodeTypeOfExpression 类的新实例。Initializes a new instance of the CodeTypeOfExpression class using the specified type.

属性

Type

获取或设置 typeof 表达式所引用的数据类型。Gets or sets the data type referenced by the typeof expression.

UserData

获取当前对象的用户可定义数据。Gets the user-definable data for the current object.

(继承自 CodeObject)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅