否。每当实现接口或重写派生类中的成员时,都需要重新声明属性。
如果您只关心ComponentModel(而不是直接反射),则有一种方法(
[AttributeProvider])从现有类型中建议属性(以避免重复),但这仅对属性和索引器用法有效。
举个例子:
using System;using System.ComponentModel;class Foo { [AttributeProvider(typeof(IListSource))] public object Bar { get; set; } static void Main() { var bar = TypeDescriptor.GetProperties(typeof(Foo))["Bar"]; foreach (Attribute attrib in bar.Attributes) { Console.WriteLine(attrib); } }}输出:
System.SerializableAttributeSystem.ComponentModel.AttributeProviderAttributeSystem.ComponentModel.EditorAttributeSystem.Runtime.InteropServices.ComVisibleAttributeSystem.Runtime.InteropServices.ClassInterfaceAttributeSystem.ComponentModel.TypeConverterAttributeSystem.ComponentModel.MergablePropertyAttribute



