Attributes helps us use class dependant values instead of instances and they help us carry some values without strong relation with our classes. But i found some restrictions on attributes. We are not able to change these values on runtime. So i a开发者_StackOverflow中文版m looking a way to use similiar concept to attributes as we have seen many example configure classes by fluent apis instead of attributes. Do you know such a ready library ? What is an alternative to use attribute concept for avoiding attribute restrictions ?
Actually in some cases you can tweak attributes at runtime - for example via TypeDescriptor
- but this only affects ComponentModel usage, not reflection usage. You can also write the attribute itself to do things like resx lookup for i18n purposes.
But other options:
- maybe a static property, perhaps following a naming convention
- a separate object model that talks about the types - a meta-model, so to speak
- a configuration file or similar
Any will work; which is best depends on exactly what you have in mind.
A good replacement of attribute in a plug-in architecture could be using smart naming conventions.
Perhaps I am missing something, but can't you just add properties with a public setter to your custom attributes? I just tried this on a implementation where I use attributes, and I am able to change this property at runtime without any problems.
Which values do you want to change?
精彩评论