Reflection - get attribute name and value on property

后端 未结 15 2213
谎友^
谎友^ 2020-11-22 04:59

I have a class, lets call it Book with a property called Name. With that property, I have an attribute associated with it.

public class Book
{
    [Author(\"         


        
15条回答
  •  庸人自扰
    2020-11-22 05:12

    If you just want one specific Attribute value For instance Display Attribute you can use the following code:

    var pInfo = typeof(Book).GetProperty("Name")
                                 .GetCustomAttribute();
    var name = pInfo.Name;
    

提交回复
热议问题