How to access the Description attribute on either a property or a const in C#?

前端 未结 4 1417
死守一世寂寞
死守一世寂寞 2020-12-15 05:33

How do you access the Description property on either a const or a property, i.e.,

public static class Group
{

    [Description( \"Specified parent-child rel         


        
4条回答
  •  眼角桃花
    2020-12-15 06:18

    You can call MemberInfo.GetCustomAttributes() to get any custom attributes defined on a member of a Type. You can get the MemberInfo for the property by doing something like this:

    PropertyInfo prop = typeof(Group).GetProperty("UserExistsInGroup",
        BindingFlags.Public | BindingFlags.Static);
    

提交回复
热议问题