How to get a custom attribute from object instance in C#

前端 未结 6 1171
眼角桃花
眼角桃花 2020-12-05 07:40

Let\'s say I have a class called Test with one property called Title with a custom attribute:

public class Test
{
    [DatabaseField(\"title\")]
    public s         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 08:13

    No, it's not possible. The reason for this is that it's the value, and not the property itself that would be sent into any custom extension method that would fetch this information. Once you get into that extension method, there's no reliable way to trace back to the property itself.

    It might be possible for enum values, but as far as properties on POCO's, it's not going to work.

提交回复
热议问题