0

I am developing a Revit addin utilizing the Prism library as my MVVM/IOC framework. The addin relies heavily on Prism's DialogService to display various dialogs for several tools.

I want to avoid hard-coding dialog names whenever using the IDialogService.ShowDialog(dialogName, dialogParams, callBackAction) function. So I am thinking of introducing a static class in the abstraction layer that holds the names of all the dialogs defined in the UI layer assembly.

Instead of maintaining this class manually, is there a way to equip my solution with a code generator that will update this class whenever I:

  • Add a new dialog sub-class to the UI project? Or
  • Register a new dialog with the IContainerRegistry.RegisterDialog<DlgUserControlType, DlgViewModelType>() ?

I'm not sure if this is a naive approach, so please feel free to point out any "smell" in it.

Samer
  • 11
  • 1
  • 6

1 Answers1

0

Yes, sure. You can use the .NET Reflection library to determine all your add-in's class names. If the new dialog sub-class follows a suitable naming convention, you can easily use Reflection to extract the dialogName, dialogParams, and callBackAction information required from the class name and its other attributes.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • As far as I know, Reflection happens after you compile. What I'm looking for is code generation in design time (for example when a new file is added to the source-code). Just like the code generated for you in the background when you add a new Win-Form for example. – Samer Jun 23 '23 at 15:59
  • You can mix compilation and reflection at will. Both can happen in real-time, and you can pass information back an forth between the two processes, cf. [dynamically compile and execute C# code fragments](https://stackoverflow.com/questions/826398/is-it-possible-to-dynamically-compile-and-execute-c-sharp-code-fragments). – Jeremy Tammik Jun 24 '23 at 11:07