Assembly.GetCustomAttributes 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此程序集的自定义属性。
重载
| GetCustomAttributes(Boolean) |
获取此程序集的所有自定义属性。 |
| GetCustomAttributes(Type, Boolean) |
获取按类型指定的此程序集的自定义属性。 |
GetCustomAttributes(Boolean)
- Source:
- Assembly.cs
- Source:
- Assembly.cs
- Source:
- Assembly.cs
- Source:
- Assembly.cs
获取此程序集的所有自定义属性。
public:
virtual cli::array <System::Object ^> ^ GetCustomAttributes(bool inherit);
public virtual object[] GetCustomAttributes(bool inherit);
abstract member GetCustomAttributes : bool -> obj[]
override this.GetCustomAttributes : bool -> obj[]
Public Overridable Function GetCustomAttributes (inherit As Boolean) As Object()
参数
返回
包含此程序集自定义属性的数组。
实现
注解
此方法实现相应的 ICustomAttributeProvider 接口方法。 因此,即使忽略参数, inherit 也必须指定该参数。
伪属性指示存在该特性时必须设置的核心元数据的位。 与扩展类型的元数据并随类型一起保存的自定义属性不同,伪属性修改类型的元数据,然后被丢弃。 某些生成的位无法使用现有反射 API 进行访问。
下表总结了反射中可用的位的不同伪属性和访问器。
| Pseudo-Attribute | 元数据位 | 反射访问器 |
|---|---|---|
| DllImportAttribute | CorPInvokeMapDLL 名称 |
对于普通方法/全局方法属性,没有 的 PInvokeMap 访问器。DLL 名称没有访问器。 |
| GuidAttribute | 存储为真正的自定义属性。 | 作为真正的自定义属性访问。 |
| ComImportAttribute | CorTypeAttr.tdImport |
Type.Attributes.Import |
| SerializableAttribute | CorTypeAttr.tdSerializable |
Type.Attributes.Serializable |
| NonSerializedAttribute | CorFieldAttr.fdNotSerialized |
FieldInfo.Attributes.NotSerialized |
| MethodImplAttribute | CorMethodImpl |
MethodInfo.GetMethodImplementationFlags()ConstructorInfo.GetMethodImplementationFlags() |
| MarshalAsAttribute | 各种位。 | 无访问器。 |
| PreserveSigAttribute | CorMethodImpl.miOLE |
MethodInfo.GetMethodImplementationFlags().OLEConstructorInfo.GetMethodImplementationFlags().OLE |
| InAttribute | CorParamAttr.pdIn |
ParameterInfo.Attributes.In |
| OutAttribute | CorParamAttr.pdOut |
ParameterInfo.Attributes.Out |
| StructLayoutAttribute | CorTypeAttr.tdLayoutSequentialCorTypeAttr.tdExplicitLayoutCorTypeAttr.tdAnsiClassCorTypeAttr.tdUnicodeClassCorTypeAttr.tdAutoClass类打包。 |
Type.Attributes.LayoutSequentialType.Attributes.ExplicitLayoutType.Attributes.AnsiClassType.Attributes.UnicodeClassType.Attributes.AutoClass无访问器。 |
| FieldOffsetAttribute | 字段偏移量。 | 无访问器。 |
AssemblyLoadAttribute |
CorAssemblyFlags |
无访问器或枚举器。 |
适用于
GetCustomAttributes(Type, Boolean)
- Source:
- Assembly.cs
- Source:
- Assembly.cs
- Source:
- Assembly.cs
- Source:
- Assembly.cs
获取按类型指定的此程序集的自定义属性。
public:
virtual cli::array <System::Object ^> ^ GetCustomAttributes(Type ^ attributeType, bool inherit);
public virtual object[] GetCustomAttributes(Type attributeType, bool inherit);
abstract member GetCustomAttributes : Type * bool -> obj[]
override this.GetCustomAttributes : Type * bool -> obj[]
Public Overridable Function GetCustomAttributes (attributeType As Type, inherit As Boolean) As Object()
参数
- attributeType
- Type
要为其返回自定义属性的类型。
返回
一个数组,它包含由 attributeType 指定的此程序集的自定义属性。
实现
例外
attributeType 为 null。
attributeType 不是运行时类型。
注解
此方法实现相应的 ICustomAttributeProvider 接口方法。 因此,即使忽略参数, inherit 也必须指定该参数。
伪属性指示存在该特性时必须设置的核心元数据的位。 与扩展类型的元数据并随类型一起保存的自定义属性不同,伪属性修改类型的元数据,然后被丢弃。 某些生成的位无法使用现有反射 API 进行访问。
下表总结了反射中可用的位的不同伪属性和访问器。
| Pseudo-Attribute | 元数据位 | 反射访问器 |
|---|---|---|
| DllImportAttribute | CorPInvokeMapDLL 名称 |
对于普通方法/全局方法属性,没有 的 PInvokeMap 访问器。DLL 名称没有访问器。 |
| GuidAttribute | 存储为真正的自定义属性。 | 作为真正的自定义属性访问。 |
| ComImportAttribute | CorTypeAttr.tdImport |
Type.Attributes.Import |
| SerializableAttribute | CorTypeAttr.tdSerializable |
Type.Attributes.Serializable |
| NonSerializedAttribute | CorFieldAttr.fdNotSerialized |
FieldInfo.Attributes.NotSerialized |
| MethodImplAttribute | CorMethodImpl |
MethodInfo.GetMethodImplementationFlags()ConstructorInfo.GetMethodImplementationFlags() |
| MarshalAsAttribute | 各种位。 | 无访问器。 |
| PreserveSigAttribute | CorMethodImpl.miOLE |
MethodInfo.GetMethodImplementationFlags().OLEConstructorInfo.GetMethodImplementationFlags().OLE |
| InAttribute | CorParamAttr.pdIn |
ParameterInfo.Attributes.In |
| OutAttribute | CorParamAttr.pdOut |
ParameterInfo.Attributes.Out |
| StructLayoutAttribute | CorTypeAttr.tdLayoutSequentialCorTypeAttr.tdExplicitLayoutCorTypeAttr.tdAnsiClassCorTypeAttr.tdUnicodeClassCorTypeAttr.tdAutoClass类打包。 |
Type.Attributes.LayoutSequentialType.Attributes.ExplicitLayoutType.Attributes.AnsiClassType.Attributes.UnicodeClassType.Attributes.AutoClass无访问器。 |
| FieldOffsetAttribute | 字段偏移量。 | 无访问器。 |
AssemblyLoadAttribute |
CorAssemblyFlags |
无访问器或枚举器。 |