简体   繁体   中英

set property attribute dynamically

I have a object name Person with properties firstName, lastname.

How can I dynamically add attribute on those public properties.

If you really mean attributes, eg

 [Description("Foo")]

then you can't add those at execution time. They're part of the metadata associated with the class. I mean, you could generate the class itself at execution time, but I'm not sure that's really what you want to do.

Could you tell us more about the bigger picture here?

You can't. Attributes are meta-data stored in the compiled assembly and it pertains to the Type Person, not to the Object Person that you have.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM