プロパティに配置されたすべてのカスタム属性を収集しようとしています。プロパティに割り当てられた同じタイプの属性が複数ありますが、それらを収集すると、結果のコレクションには特定のタイプの最初の属性のみが含まれます。
属性クラス
[AttributeUsage(System.AttributeTargets.Property,
AllowMultiple = true)]
public class ConditionAttribute : Attribute{...}
使用法:
[ConditionAttribute("Test1")]
[ConditionAttribute("Test2")]
[ConditionAttribute("Test3")]
public Color BackColor{get; set;}
次に、Prop「BackColor」を含むクラスを持つオブジェクト「value」のすべての Prop をループすると、次のようになります。
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(value))
{
foreach (Attribute attribute in property.Attributes)
{ ... }
....
}
コレクションプロパティ。属性には、タイプ「ConditionAttribute」の 1 つの属性のみが含まれます。「Test1」を持つ属性です。他のものは無視されます;-(
AllowMultiple は Property Attributes では機能しませんか?
前もって感謝します
ヘンリク