0

I am modernizing a lot of VB.NET code to CSharp and I need to convert dozens of dialogs to conform with our new MVP standard. I'm trying to write snippets so I can more easily bang out the boiler plate stuff but I find it annoying having to type in the interface names each time for every M/V/P, especially in the Presenter for the CTOR and private properties.

I want to do something like this: private I$namespace$View _View;

Each MVP will be in its own folder, thus in its own namespace.

I tried searching for a solution but everything seems pretty out dated (last posts being 2015/19). These were the two posts I found but they seem to only refence being able to define custom snippets for new languages, not new functions for C#.

Question about getting namespace in snippet (not for C#, but extended language)

Question about defining custom functions for snippets (very old question and answer, 10+ years)

As far as I can tell there was no way to extend this functionality, is this still the case? The first question talked about using macros within snippets to get the namespace but I couldn't find anything online about that.

Any help or documentation on creating really advanced snippets would be nice.

1
  • "no way to extend this functionality, is this still the case?" - Yes. Visual Studio's snippets support only the most basic needs as they existed when the feature was created. Microsoft does not seem to be interested in enhancing it, only breaking it from time to time (e.g. name suggestions) because they forget that it exists. I'm sure there are extensions that provide more advanced snippet functionality, but that's off-topic here. Commented Sep 5, 2023 at 19:28

1 Answer 1

1

I ended up just creating a custom ItemTemplate. The customization of ItemTemplate's is more powerful in terms of what I was looking to do. Instead of having to create all the MVP files then do the boilerplate stuff I just created an ItemTemplate that does it all in one go. I found this link helpful for figuring out which template variables I could use when creating the files.

Sign up to request clarification or add additional context in comments.

1 Comment

I was thinking maybe a T4 template would work. Or a code generator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.