CodeTypeReference.BaseType Property

Definition

Gets or sets the name of the type being referenced.

public string BaseType { get; set; }

Property Value

The name of the type being referenced.

Remarks

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

Notă

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 ("+").

Notă

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.

Applies to

Produs Versiuni
.NET 8 (package-provided), 9 (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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9