C#: How to add an attributes to an object at run-time?

后端 未结 7 1894
孤独总比滥情好
孤独总比滥情好 2020-12-30 09:00

As an entity class, I want to add an attributes at run-time, how should I do?

相关标签:
7条回答
  • 2020-12-30 09:31

    Attributes are part of the meta-data of a type and so they are hardcoded in the compiled assembly (that's also why you are only allowed to use some primitive types and not arbitrary data at attributes).

    The consequence is that you can't add any attributes to a type at runtime. But there are various alternative techniques. You could use simple dictionaries or something more powerful like attached dependency properties.

    0 讨论(0)
提交回复
热议问题