Čítať v angličtine Upraviť

Zdieľať cez


CodeTypeOfExpression Class

Definition

Represents a typeof expression, an expression that returns a Type for a specified type name.

C#
public class CodeTypeOfExpression : System.CodeDom.CodeExpression
C#
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeTypeOfExpression : System.CodeDom.CodeExpression
Inheritance
CodeTypeOfExpression
Attributes

Examples

The following example demonstrates use of a CodeTypeOfExpression to represent a typeof expression.

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

Remarks

A CodeTypeOfExpression represents a typeof expression that returns a Type at runtime.

The Type property specifies the data type to return a Type object for.

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.

Constructors

CodeTypeOfExpression()

Initializes a new instance of the CodeTypeOfExpression class.

CodeTypeOfExpression(CodeTypeReference)

Initializes a new instance of the CodeTypeOfExpression class.

CodeTypeOfExpression(String)

Initializes a new instance of the CodeTypeOfExpression class using the specified type.

CodeTypeOfExpression(Type)

Initializes a new instance of the CodeTypeOfExpression class using the specified type.

Properties

Type

Gets or sets the data type referenced by the typeof expression.

UserData

Gets the user-definable data for the current object.

(Inherited from CodeObject)

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

Produkt Verzie
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also