0

I'm using OOP and MVVM in a WPF c# application. The goal is for the resulting object (data-bound to user interface) to accurately represent a product. One specific area of the product is highly configurable. For conceptual purposes, imagine a boat which can have various means of propulsion. A submerged prop motor or above water fan motor may be attached at the stern, and they would have very different properties.

At the model level, I could have an interface typed property for this PropulsionDevice, with the interface defining all the required information I need for pricing and weighting the finished product. How to assign this property based on user input is where I am unsure what to do. Creating an enumeration with an item for each class implementing my interface, and presenting it in a ComboBox seems clunky and naive (the disconnect between the enum item and the class seems wrong). But, I'm not sure if meta-programming with Custom Attributes or using Reflection would be a better option. Maybe there is another option?

Any suggestions on how to allow for flexibility in my c# classes, as well as how to present this in the UI?

0

I see no problem in using reflection to find each class that implements the desired interface and presenting it in a ComboBox. You could even use IoC to do this, so you don't have to worry about it yourself.

  • thanks for the response. I like the idea of an IoC container providing the options for me. The model I am referring to is contained in a library project, which is then referenced from the WPF application. Would it be best to keep the View/DataTemplate portion of the implementing classes in the WPF application, or somehow expose it through the container as well? I'm thinking if a new "configuration" were ever offered it would require changes in the library as well as in the WPF application. The more I think about it though, that's kind of true for the entire library... bad? – Ethan Jan 20 '14 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.