Edit

Bagikan melalui


CodeTypeReference.BaseType Property

Definition

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

Applies to