CodeTypeReference.BaseType 属性
定义
获取或设置所引用的类型的名称。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
属性值
所引用的类型的名称。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.
备注
属性的名称可能会产生误导。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. 例如,的 BaseType 值 System.Collections.Generic.Dictionary`2[[System.String], [System.Collections.Generic.List`1[[System.Int32]]]] 为 System.Collections.Generic.Dictionary`2 。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
本部分中的信息适用于 CodeDom 提供程序开发人员,仅适用于符合 CLS 的语言。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. 可以在由属性返回的中找到泛型类型参数 CodeTypeReferenceCollection TypeArguments 。The generic type arguments can be found in the CodeTypeReferenceCollection returned by the TypeArguments property. 和返回的值 BaseType TypeArguments 包含与反射返回的类型的值相同的内容。The values returned by BaseType and the associated TypeArguments contain the same content as the value of the type returned by reflection.
例如,一个构造 Dictionary<TKey,TValue> 的,其中 K 是一个字符串,并且 V 是一个由整数构造的,它由 List<T> 反射表示,如下 (移除了程序集信息) :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]]]]
以递归方式分析的 BaseType 属性 CodeTypeReference 将 Dictionary<TKey,TValue> 生成与上述反射表示形式相同的字符串:Recursively parsing the BaseType property from the CodeTypeReference for Dictionary<TKey,TValue> yields the same strings as the reflection representation above:
BaseType父的属性 CodeTypeReference 返回以下内容:The BaseType property for the parent CodeTypeReference returns the following:
System.Collections.Generic.Dictionary`2BaseType集合中第一个对象的属性 CodeTypeReference TypeArguments 返回以下内容:The BaseType property for the first CodeTypeReference object in the TypeArguments collection returns the following:
System.StringBaseType集合中第二个 CodeTypeReference 对象的属性 TypeArguments 返回以下内容:The BaseType property for the second CodeTypeReference object in the TypeArguments collection returns the following:
System.Collections.Generic.List`1TypeArguments对象中的属性 CodeTypeReference
System.Collections.Generic.List`1返回以下内容:The TypeArguments property in the CodeTypeReference object forSystem.Collections.Generic.List`1returns the following:System.Int32
分析关联值时应使用类型参数计数 TypeArguments 。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 ("+").
备注
创建泛型时 CodeTypeReference ,建议的做法是将类型参数指定为对象, CodeTypeReference 或使用采用的构造函数 Type 。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. 使用从字符串创建的构造函数 CodeTypeReference 可能会导致无法发现类型参数错误。Use of the constructor that creates a CodeTypeReference from a string can lead to undiscoverable type-argument errors.