0

I'm basically asking if we can fake some sort of multiple inheritance on attribute classes. I have some view models with a lot of properties that are all getting the same combinations of attributes for field length, formatting, some custom stuff, etc. There are probably on the order of 50 fields like this. Some of the attributes have constants in them.

This seems really bad as code duplication. If I want to change the formatting or any of these constants a bit, I have to find and fix every field individually. Is it possible for me to create some single [MyCustomFieldType] attribute that simply behaves as all of those other attributes combined, so it stays DRY?

edit: What I mean about code duplication is that each property has multiple attributes; I'm not referring to the fact that there are multiple properties. I understand that even if I had one attribute to place, I would have to place it many times. But then at least I have one place (the attribute class) to change things like format strings or other numeric constant parameters.

Tesserex
  • 17,166
  • 5
  • 66
  • 106
  • Sorry for the questions but why do you need multiple inheritance to do that. What about the single inheritance model prevents this? – paparazzo Oct 26 '12 at 15:27

1 Answers1

0

I think I see what you're getting at here, and for viewmodel properties, I'm afraid you won't be able to combine the ones you want to. Please update your question to show some examples of attributes and constants you want to combine. Have you thought about stashing your constants in a Resources resx file? You could then use some of the attribute properties to retrieve constants from that file, which should make it DRYer. However, you would still need to have the combinations of attributes on each property.

danludwig
  • 46,965
  • 25
  • 159
  • 237