我想收集放置在属性上的所有自定义属性。有多个相同类型的 Attributes 分配给了 Property,但是在收集它们时,生成的集合只包含特定类型的第一个 Attribute:
属性类
[AttributeUsage(System.AttributeTargets.Property,
AllowMultiple = true)]
public class ConditionAttribute : Attribute{...}
用法:
[ConditionAttribute("Test1")]
[ConditionAttribute("Test2")]
[ConditionAttribute("Test3")]
public Color BackColor{get; set;}
现在,当遍历对象“值”的所有道具时,其类包含道具“BackColor”:
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(value))
{
foreach (Attribute attribute in property.Attributes)
{ ... }
....
}
集合属性。属性仅包含一个“ConditionAttribute”类型的属性:具有“Test1”的属性。其他的被忽略;-(
那么 AllowMultiple 不适用于 Property Attributes 吗?
提前致谢
亨里克