jeudi 27 septembre 2018

Add CustomAttribute to class and propagate it to its properties

I am trying to define a CustomAttribute with class level and I would like this attribute is propagated to all the properties of the class.

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
public class MyCustomAttribute : Attribute
{
}

[MyCustom]
public class MyClass
{
    public int A { get; set; }
    public int B { get; set; }
    public int C { get; set; }
}

I would like the properties A, B and C have also MyCustomAttribute assigned. I know I can define the Attribute for each property. But I want to define the Attribute in the class level.

Is it possible?





Aucun commentaire:

Enregistrer un commentaire