Generate generic class?

9 views
Skip to first unread message

Paul Batum

unread,
Dec 6, 2008, 5:11:16 AM12/6/08
to TDD Productivity Plugin
Hi Eric,

A minor request. Today I wrote this code:

var classMap = new ClassMap<Artist>();

ClassMap was highlighted red because it wasn't defined. I then hit
"create in FluentNHibernate" and it created the class, but it stayed
red because the created class wasn't generic. If I choose the normal
"create class" resharper option, its smart enough to make a generic
class, but of course its created in the same file. If I then try to
use resharper to move it over to the project under test, its not put
in the right spot. So using the default resharper option is kinda
sucky, its actually worse because its easier to use your option and
then find the class it made and switch it over to generic. But of
course it would be -even nicer- if the "create in <project>" option
was smart enough to make the class generic.

I don't make a huge number of generic classes so its not causing me a
lot of pain, but I thought it might be worth making the suggestion
anyway.

Eric Hexter

unread,
Dec 6, 2008, 9:41:04 AM12/6/08
to tdd-product...@googlegroups.com
Great... I like to hear of more use cases.  I can see value in this. I will get this on the list, of refactorings to support.


Eric Hexter

unread,
Dec 12, 2008, 7:27:02 AM12/12/08
to tdd-product...@googlegroups.com
I looked into this. and it should not be to bad to implement.  The question is this.  How should the generic names be defined...
ie  var foo = new Bar<string,bool>();


this should generate something like this:


public class Bar<T1,T2>
{
}


Is following the T1,T2...ect approach usable?  

Paul Batum

unread,
Dec 12, 2008, 6:33:06 PM12/12/08
to tdd-product...@googlegroups.com
That should be fine.

So I'm curious, will you have to develop this functionality yourself? There isn't a way to hook into resharper's templating and get it to do it for you? Because resharper already knows how to make a generic class, the problem is that its not smart enough to give you different options about where you want it put (hence the TDD productivity plugin).

I don't really know anything about resharper plugin development. I was just curious because it sounds like you are going to have to reimplement something that resharper can already do.

Paul Batum

Eric Hexter

unread,
Dec 12, 2008, 11:07:42 PM12/12/08
to tdd-product...@googlegroups.com
Actually, I am not using resharper to create the class because of a "bug/ as designed feature" in resharper of adding folders, and having the resharper project wrapper synchronize when a new folder is added. 

 I implemented the folder creation and file creation three different ways and the two ways that allowed me to use the resharper folder live templates had a limitation that I could not resolve.  The last and finally way ended up leaving me have to do a large portion of the file creation logic.  It took me over a month to come to the current implementation and I would say it is far from my first choice as far as what type of power it gives me..  If you ever have a chance look through the resharper code in reflector and you will get an idea of some of the issues with the "Open API"  there are a lot of internal sealed classes that are quite useful in there assemblies. Sounds like a certain framework implementation i know called Asp.net.

The good news is that their api does expose the fact that then type decleration is generic and includes the number of generic arguments that are defined. So that portion of the api is pretty easy to work with and will be consistent with resharpers existing functionality.   

Paul Batum

unread,
Dec 12, 2008, 11:20:50 PM12/12/08
to tdd-product...@googlegroups.com
I see, thanks for satisfying my curiosity.
Reply all
Reply to author
Forward
0 new messages