CodeTypeReference.BaseType Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the name of the type being referenced.
public:
property System::String ^ BaseType { System::String ^ get(); void set(System::String ^ value); };
public string BaseType { get; set; }
member this.BaseType : string with get, set
Public Property BaseType As String
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.
Note
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 BaseType property for the parent CodeTypeReference returns the following:
System.Collections.Generic.Dictionary`2
The BaseType property for the first CodeTypeReference object in the TypeArguments collection returns the following:
System.String
The BaseType property for the second CodeTypeReference object in the TypeArguments collection returns the following:
System.Collections.Generic.List`1
The TypeArguments property in the CodeTypeReference object for
System.Collections.Generic.List`1
returns the following:System.Int32
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 ("+").
Note
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.