image

I really like the Code Rush dynamic type stuff, introduced with version 2, but I never really understood how it worked until this week.

I often find that I use the "pl." family of templates and then go back to change the List<> to an IList<>. I got tired of this, so decided to see if there was a way I could add IList<> as a mnemonic somehow.

After checking out the "p?Generic1Type?" template, and reading the description, I saw somewhere that it read the list of type mnemonics from a dynamic list. I then found this forum post, where Marc Miller explains where to find the list.

So I added "il" as a mnemonic for "IList". Now I can type "pil." and get an IList<> property, or "mil." and get an IList<> returning method, or "pild8" and get an IList<DateTime> property.

The only tricky part was figuring out how this Dynamic Lists dialog works. The add button is disabled. After staring at it for 5 minutes, trying to figure out how to enable it, I tried changing the mnemonic of an existing one, and suddenly add was enabled.


 
Categories: CodeRush

I might be one of the few NHibernate users using Code Rush (and not resharper,) but here goes:

Using NHibernate, I need all the properties and methods on my model classes to be virtual. It's tedious to go and add virtual to them all the time, and CodeRush is perfectly capable of doing this for us.

The CodeRush "p" family of templates look like this:

image

Notice the #PropertyDefaultScope template. This is where is says "public" or "private", and also happens to be where "static" gets inserted if we're in a static class. This seems like a good place to insert my "virtual".

image

There's #StaticIfNeeded, the one that decides to add "static." Let's see how that works. Maybe we can make a "#VirtualIfPossible#" template that is at least a little smart about this - i.e., doesn't add virtual if we're doing a static method, etc.

image

Notice that it has to be in a static class to work. Let's do that same thing, but when we're _not_ in a static class:

image

Now we can add that to the #PropertyDefaultScope template:

image

Now when I declare properties, they will be virtual by default, making it easier to build NHibernate model classes, as well as use Rhino Mocks and other things that thrive on virtualness:

image


 
Categories: nhibernate | CodeRush