Design-time Code Auto Generation

Hi,

Is there a way to auto-generate code after particular changes are made to the source code (without manually compiling)?
For example, I would like to automatically add container interface/class mappings when a new wpf form class with a predefined naming convention is added to the source code.
Not sure if Analyzers can be utilized to do this.
Suggestions are greatly appreciated.

Thanks!

0
1 comment

Hi Sam Najjar

Thank you for the request. 

It seems like a code generation request for a framework, not for IDE itself. The "automatic" code generation upon source code change would require some system for watching the source code changes, which is outside the capabilities of most IDEs.

I suggest using Live Templates to see if that boosts your productivity. You can find and customize an existing interface template in File | Settings | Editor | Live Templates | C#.

For your specific scenario (when a new WPF form class with a predefined naming convention is added):

  • You would have to customize or create a new Live Template that defines the container interface/class mapping structure.
  • When you create a new WPF form that fits your naming convention, you can apply your live template to generate the mapping code.

While this mechanism requires a manual trigger, it can significantly speed up the code generation process.

I hope this helps!

0

Please sign in to leave a comment.