CodeTypeReference Class

 

Represents a reference to a type.

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

System.Object
  System.CodeDom.CodeObject
    System.CodeDom.CodeTypeReference

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeTypeReference : CodeObject

NameDescription
System_CAPS_pubmethodCodeTypeReference()

Initializes a new instance of the CodeTypeReference class.

System_CAPS_pubmethodCodeTypeReference(CodeTypeParameter)

Initializes a new instance of the CodeTypeReference class using the specified code type parameter.

System_CAPS_pubmethodCodeTypeReference(CodeTypeReference, Int32)

Initializes a new instance of the CodeTypeReference class using the specified array type and rank.

System_CAPS_pubmethodCodeTypeReference(String)

Initializes a new instance of the CodeTypeReference class using the specified type name.

System_CAPS_pubmethodCodeTypeReference(String, CodeTypeReference[])

Initializes a new instance of the CodeTypeReference class using the specified type name and type arguments.

System_CAPS_pubmethodCodeTypeReference(String, CodeTypeReferenceOptions)

Initializes a new instance of the CodeTypeReference class using the specified type name and code type reference option.

System_CAPS_pubmethodCodeTypeReference(String, Int32)

Initializes a new instance of the CodeTypeReference class using the specified array type name and rank.

System_CAPS_pubmethodCodeTypeReference(Type)

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

System_CAPS_pubmethodCodeTypeReference(Type, CodeTypeReferenceOptions)

Initializes a new instance of the CodeTypeReference class using the specified type and code type reference.

NameDescription
System_CAPS_pubpropertyArrayElementType

Gets or sets the type of the elements in the array.

System_CAPS_pubpropertyArrayRank

Gets or sets the array rank of the array.

System_CAPS_pubpropertyBaseType

Gets or sets the name of the type being referenced.

System_CAPS_pubpropertyOptions

Gets or sets the code type reference option.

System_CAPS_pubpropertyTypeArguments

Gets the type arguments for the current generic type reference.

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

A CodeTypeReference object is used to represent a type for CodeDOM objects. When CodeDOM types have a Type property, it is of type CodeTypeReference. For example, the CodeMemberField.Type property is a CodeTypeReference that represents a field's data type.

A CodeTypeReference can be initialized with a Type object or a string. It is generally recommended to use a Type to do this, although it may not always be possible. If initializing an instance of this class with a string, it is strongly recommended to always use fully qualified types, such as "System.Console" instead of just "Console", because not all languages support importing namespaces. Array types can be specified by either passing in a type object for an array or using one of the constructors that accept rank as a parameter.

The BaseType property specifies the name of the type to reference. For references to array types, the ArrayElementType property indicates the type of the elements of the array, and the ArrayRank property indicates the number of dimensions in the array.

The following example demonstrates use of a CodeTypeReference to represent a reference to a type.

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

.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: