I’ve recently been playing around with creating a Visual Studio template to create a default set of classes and interfaces for a Model View Controller. Having never done anything with Visual studio templates before (other than use them), I think it turned out quite well. That being said, there was one thing that took a bit of a workaround.
When creating a Model View Controller (or MVC for short), I wanted the following classes/interfaces:
[Something]View (in this case, a Windows form)
… where [something] is the name of the actual MVC you want to create.
The issue that I ran into was in the actual template code. I was using the $safeitemname$ template parameter where I needed it. Unfortunately this didn’t quite work well in the Controller, as the value of the $safeitemname$ being passed into the controller already was “SomethingController”, not just “something”. The workaround for this was to use the $fileinputname$ template parameter instead. In this case the value of $fileinputname$ was just “something”, not “SomethingController”. All the examples out there seem to just show $rootnamespace$ and $safeitemname$. Changing it to the $fileinputname$ worked like a charm.
So, moral of the story: Try using $fileinputname$, not just $safeitemname$.
I’m almost tempted to create one of these for GameScreens in my current code that takes care of game screen management, sort of like the XNA sample. It would make adding a new GameScreen an absolute snap.