I am proud to announce two Visual Studio 2010 Extensions that are supposed to make development easier and more efficient. Yesterday I also managed to get my German website up to date, so check it out at www.neokc.de. This is also my first blog entry since Windows Live Spaces, which I liked very much, got closed down.
Logging changes with MethodLog
In my current position there is not much time in my life that I can spend on programming and related stuff, so this is all happening a little bit delayed. I published my first ever Visual Studio Extension in early September but could not write about it until now. I named it MethodLog and what it does is quite shortly to describe. Every change that the user makes to a method, is logged as a comment on that method, containing a running number and a current date and time.
The image above shows how this looks in Visual Studio. You can download this extension on my German website at www.neokc.de/programme/vsix/methodlog.htm or directly at the Visual Studio Gallery at http://visualstudiogallery.msdn.microsoft.com/en-US/b86ec350-26ad-4323-a297-9ffc38038053.
Modeling states and generating code with StatePatternModeler
The other extension that I am announcing is called StatePatternModeler. The caption of this blog post is referring to this one, since it makes Model Driven Development (MDD) easy in Visual Studio. It does not provide for an entire solution to MDD but does solve the development of stateful applications with models. In my previous blog post I was already describing how this could be accomplished with a custom UML Profile and a T4 template file that I created. If you have not read that article, go ahead and do so now, if you are interested in the raw mechanics.
The StatePatternModeler extension just wraps the UML Profile and the T4 template into a Visual Studio 2010 Extension. It provides a Project Template for the UML State Model and an Item Template for the T4 template that generates the code and a derived behavior class to apply custom logic to the state machine.
These templates make it easy to work with the UML Profile and the code generation and therefore allow an easy way to work with state machines in C#.
The images above show how this looks in Visual Studio. You can download this extension on my German website at www.neokc.de/programme/vsix/statepatternmodeler.htm or directly at the Visual Studio Gallery at http://visualstudiogallery.msdn.microsoft.com/en-US/c7bcfe24-3b1e-4eb8-8956-48d61d58fa56. StatePatternModeler only works with Visual Studio 2010 Ultimate, since it is relying on the UML Modeling Tools for the State Model Project Template.
A type-safe ViewModel base class
The last thing that mattered to me today and that I want to write about is how you can create a type-safe base class for your ViewModel in WPF or Sivlerlight. For the projects that I was doing so far, I did not need to use the MVVMlight framework. Though, I needed a base class for my ViewModels that does not use strings in order to notify property changes. Having strings can be the source of much frustration since they don’t survive refactoring. The approach that I am using allows you to have a ViewModel like below.
Ignore everything but line 17. There I notify about a change of the Counter property in a type-safe manner. Pretty cool, if you would ask me! The code of the ViewModelBase class is very simple as well, like you can see below.
The trick is to use a Linq expression that you can parse and get the name of the property, like I do in lines 22 to 25. Now you can refactor all you like and still get a compiling output. Actually, refactoring can be done including strings as well with some tools already. Type-safety as well is also not quite true, since the types don’t matter at all. Everything that is inheriting from object can be used to notify a change of it. It is just more type-safe than strings, so meta-type-safe would be a better term to describe it.