Jon Skeet's solution is good if you allow multiple attributes of the same type to be declared in a property. (AllowMultiple = true)
Example:
[Table(HeaderText="F. Name 1")] [Table(HeaderText="F. Name 2")] [Table(HeaderText="F. Name 3")] public string FirstName { get; set; }
In your case, I would suggest that you only need one attribute, allowed for each property. In this case, you can access the properties of the custom attribute with:
var tableAttribute= propertyInfo.GetCustomAttribute<TableAttribute>(); Console.Write(tableAttribute.HeaderText); // Outputs "F. Name" when accessing FirstName // Outputs "L. Name" when accessing LastName
Scubasteve
source share