CodeCastExpression Class

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Represents an expression cast to a data type or interface.

Namespace:   System.CodeDom
Assembly:  System (in System.dll)

System.Object
  System.CodeDom.CodeObject
    System.CodeDom.CodeExpression
      System.CodeDom.CodeCastExpression

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeCastExpression : CodeExpression

NameDescription
System_CAPS_pubmethodCodeCastExpression()

Initializes a new instance of the CodeCastExpression class.

System_CAPS_pubmethodCodeCastExpression(CodeTypeReference, CodeExpression)

Initializes a new instance of the CodeCastExpression class using the specified destination type and expression.

System_CAPS_pubmethodCodeCastExpression(String, CodeExpression)

Initializes a new instance of the CodeCastExpression class using the specified destination type and expression.

System_CAPS_pubmethodCodeCastExpression(Type, CodeExpression)

Initializes a new instance of the CodeCastExpression class using the specified destination type and expression.

NameDescription
System_CAPS_pubpropertyExpression

Gets or sets the expression to cast.

System_CAPS_pubpropertyTargetType

Gets or sets the destination type of the cast.

System_CAPS_pubpropertyUserData

Gets the user-definable data for the current object.(Inherited from CodeObject.)

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

CodeCastExpression can be used to represent an expression cast to a different data type or interface.

The Expression property indicates the CodeExpression to cast. The TargetType property indicates the type to cast to.

This example demonstrates using a CodeCastExpression to cast a System.Int32 value to a System.Int64 data type.

// This CodeCastExpression casts an Int32 of 1000 to an Int64.        
CodeCastExpression castExpression = new CodeCastExpression(
    // targetType parameter indicating the target type of the cast.
    "System.Int64",
    // The CodeExpression to cast, here an Int32 value of 1000.
    new CodePrimitiveExpression(1000) );    

// A C# code generator produces the following source code for the preceeding example code:

// ((long)(1000));

.NET Framework
Available since 1.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: