Uredi

CodeTypeOfExpression Class

Definition

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

public ref class CodeTypeOfExpression : System::CodeDom::CodeExpression
public class CodeTypeOfExpression : System.CodeDom.CodeExpression
type CodeTypeOfExpression = class
    inherit CodeExpression
Public Class CodeTypeOfExpression
Inherits CodeExpression
Inheritance
CodeTypeOfExpression

Examples

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

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

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

Name Description
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

Name Description
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)

Applies to

See also