Reputation: 12544
How can I make a description for a property and receive it via system.reflection ?
Upvotes: 1
Views: 85
Reputation: 81660
There is already an attribute for it:
System.ComponentModel.DescriptionAttribute
although you can make yours if you want.
Upvotes: 1
Reputation: 1038720
You could use a custom attribute:
public class FooAttribute : Attribute
{
public string Description { get; set; }
}
public class Bar
{
[Foo(Description = "Some description")]
public string BarProperty { get; set; }
}
public class Program
{
static void Main(string[] args)
{
var foos = (FooAttribute[])typeof(Bar)
.GetProperty("BarProperty")
.GetCustomAttributes(typeof(FooAttribute), true);
Console.WriteLine(foos[0].Description);
}
}
Upvotes: 3