Base on This Answer, I can get description attribute from class Property
as follow:
public class A
{
[Description("My Property")]
public string MyProperty { get; set; }
}
I can get Description
value, as follow:
// result: My Property
var foo = AttributeHelper.GetPropertyAttributeValue<A, string, DescriptionAttribute, string>(x => x.MyProperty, y => y.Description);
and now, What changes Must I do in this helper to get description from cosnt
fields
as follow:
public class A
{
[Description("Const Field")]
public const string ConstField = "My Const";
}
// output: Const Field
var foo = AttributeHelper.GetPropertyAttributeValue<A, string, DescriptionAttribute, string>(x => x.ConstField, y => y.Description);
Getting value of objects const field by reflection:
Example: