views:

109

answers:

3

This probably isn't possible, but it's annoying enough to try...

For convenience sake I'd like to be able to select "Go to definition" on a property or method on a variable defined as an interface and have Visual Studio go to the concrete implementation instead of the interface. Is there an attribute or something that I can use to instruct Visual Studio what the default concrete type for an interface is?

Update

I should mention that the reason this would be nice is because we're using dependency injection. So pretty much every object has an interface.

A: 

If a variable is declared as an interface, then any number of concrete objects that implement that interface could be assigned to your variable. At design time, there is no way the compiler could know what concrete type of object might be assigned to your interface variable.

I've never heard of a default concrete type for an interface - if someone else has, I'd be interested to know how a default might be used.

Matt Hamsmith
A: 

I hear ReSharper and Visual Assist X have this functionality, but I was hoping for something free. :(

adam0101
+3  A: 

DXCore would certainly support the creation of a plugin to do something like this. It really is very much easier to make addins than any other method I have come across.

If you're interested in doing this yourself the DXCore can be installed through the Free Coderush Xpress available from http://www.devexpress.com/crx

Can you elaborate on what sort of attribute you'd like to be able to place. :)

Seems as if the attribute might not be able to reference a type directly since that would require a circular reference. Perhaps a string giving the fully qualified "Namespace.ClassName"

I can be reached on twitter via http://twitter.com/rorybecker or email via Rory[NothingGoesHere]Becker@[gmail].[com]. If you'd prefer a more interactive conversation :)

I will ammend this answer as we progress :) I might even build this for you. :)

Rory Becker
I installed Coderush Xpress and suggested that all my coworkers install it too. It's very cool. But I'm not seeing how you use it to create an add-in. How would I get started?
adam0101
Ok well you can create a new plugin using File\New Project and selecting Standard plugni from the DXCore section. After this you might want to read up here -> http://code.google.com/p/dxcorecommunityplugins/wiki/PluginResources where you wil find some links to specific tutorials. I am writing new ones all the time and Iusually link them from there :)
Rory Becker
Okay, while trying to make this I found an example that someone else already did. http://community.devexpress.com/blogs/markmiller/archive/2008/12/02/new-coderush-plug-in-jump-to-implementer.aspx but he says to use it you choose from the "Jump To.." menu. I don't have that menu. Do you happen to know if it is not available in the free version of CodeRush?
adam0101
lol... that someone, is Mark Miller (Chief architect of Coderush :) )I don't think that the Jump to Menu is available in CRX, but I'll have to check in the morning.
Rory Becker
I'm also not convinced that what Mr miller is doing on his post is the same as what you are after. You can however use an "Action" as the initial trigger for whatever code you create. This allows you to bind any functionality you create to a keystroke. See http://rorybecker.blogspot.com/2009/08/how-to-bind-key-in-coderush.html. For a quick sample of an Action-based plugin see http://rorybecker.blogspot.com/2009/04/crhelloworld-your-first-dxcore-plugin.html
Rory Becker
It looks like with his method you would right-click on an Interface type and you'd get a list of classes that implement that method. That's nicer than having nothing. It'd be nicer if you could also right-click on a variable declared as an Interface or a method that returns an Interface and get the same thing. It seems feasible, so I'll give you credit for the answer, but I just don't have time to be making add-ins. Hopefully someone else will make something someday that I can just install. Thanks.
adam0101
I'm happy to enter into discussion with you on this and perhaps even make it for you... just for fun ... No charge or anything silly like that.... contact me ... (roryBecker gmail com) Hard to spec stuff like this out on SO :) We can come back and adjust the answer to reflect whatever we come up with :)
Rory Becker