Export (0) Print
Expand All

CodeTypeReference.BaseType Property

Gets or sets the name of the type being referenced.

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

public string BaseType { get; set; }

Property Value

Type: System.String
The name of the type being referenced.

This property contains the name of the type unless it is an array type, in which case it is the array element type.

NoteNote

The name of the property may be misleading. This property contains just the type name with any array adornments or generic type arguments removed, not the base or parent type as might be expected. For example, the BaseType value for System.Collections.Generic.Dictionary`2[[System.String], [System.Collections.Generic.List`1[[System.Int32]]]] is System.Collections.Generic.Dictionary`2.

Representation of Generic Types

The information in this section is intended for CodeDom provider developers and only applies to CLS-compliant languages. The return value can contain generic types. Generic types are formatted with the name of the type followed by a grave accent ("`") followed by a count of the generic type arguments. The generic type arguments can be found in the CodeTypeReferenceCollection returned by the TypeArguments property. The values returned by BaseType and the associated TypeArguments contain the same content as the value of the type returned by reflection.

For example, a constructed Dictionary<TKey, TValue> where K is a string and V is a constructed List<T> of integers is represented by reflection as the following (with the assembly information removed):

System.Collections.Generic.Dictionary`2[[System.String], [System.Collections.Generic.List`1[[System.Int32]]]]

Recursively parsing the BaseType property from the CodeTypeReference for Dictionary<TKey, TValue> yields the same strings as the reflection representation above:

The type argument count should be used when parsing the associated TypeArguments values. The common practice is to remove the type argument count from the generated code, but the practice is compiler specific. It is important to note that the type argument count can be found within a nested type name, in which case it is followed by a plus sign ("+").

NoteNote

When creating a generic CodeTypeReference, the recommended practice is to specify the type arguments as CodeTypeReference objects or use the constructor that takes a Type. Use of the constructor that creates a CodeTypeReference from a string can lead to undiscoverable type-argument errors.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft