Freshblood
Freshblood

Reputation: 6431

What is alternative of attributes?

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 am 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 ?

Upvotes: 6

Views: 1513

Answers (3)

Steven Jeuris
Steven Jeuris

Reputation: 19100

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?

Upvotes: 0

Felice Pollano
Felice Pollano

Reputation: 33252

A good replacement of attribute in a plug-in architecture could be using smart naming conventions.

Upvotes: 0

Marc Gravell
Marc Gravell

Reputation: 1062865

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.

Upvotes: 3

Related Questions