This is an example of my general problem:
I have different implementations of ITextSearcher to search for something. Each implementation has different settings that can be edited by the user. So I can’t make a general editable view for the implementations (because the settings can’t be abstracted by an interface).
I have developed a simple library that helps in this situations. It allows to declaratively tag a class and it’s properties with view information. A view generator uses this information to render the class. This is an example:
[Editable]
internal class TermSearcher : ITextSearcher
{
[Editable(Name="Search Expression", Order = 1)]
public string Expression
{...}
[Editable(Name="Match Similar Characters", Order = 2)]
public bool MatchSimilarChars
{...}
// rest of the implementation ...
}
Is there a better solution?
Yes. In WPF or Silverlight you can create a
DataTemplatefor the various instantiations of ITextSearcher. You can then use aDataTemplateSelectorto pick the appropriate DataTemplate given an instance of anITextSearcherSince you tagged the post with MVVM I’m assuming you are using WPF