What's the simplest most elegant way to utilize a custom attribute

后端 未结 3 1636
天涯浪人
天涯浪人 2020-12-20 23:50

So a little confession, I\'ve never written an attribute class. I understand they serve the purpose of decorating classes with flags or extra functionality possibly.

3条回答
  •  孤城傲影
    2020-12-21 00:39

    Attributes are always used with reflection. They are baked into the metadata of the types during compile time and the only way to read them is through reflection. Attributes are used when you want write a type and you want to associate some metadata with it which could be used by consumers of this type.

提交回复
热议问题