Extending Intellisense: TypeFinder Macro

Namespaces in .NET are great! But how many times do you find yourself typing Private r As xmlreader, and then noticing that there is no Imports/using statement for the System.Xml Namespace? Then you would have to scroll to the top of your document and add the Imports/using statement by hand. Alternatively you could choose to add the namespace to your declaration: Private r As System.Xml.XmlReader. Since we are all developers, why not develop something to help developers with this tedious task of namespace lookups?

The first version of this macro was published some time ago. Thanks to Yves Hanoulle, Thomas Freudenberg and Guillaume Roberge, a new version is available. Changes:

  • Check if the “Imports/using NamespaceX“ statement is already present in the code.
  • Code cleanup and improvements.

The new version (with installation instructions) can be found on this page: http://dotnet.leadit.be/typefinder (temporary down, alternative: http://typefinder.mine.nu). A compiled Macro Project and the source code in plain text can be downloaded.

6 Comments

  • Thanks for the credits :-)



    However, I did some more customization some time ago. I will compare it to your new version and maybe suggest some more improvements ;-)



    Regards,

    Thomas

  • Really good macro...I don't know how easy it will be, but is there any way to have it look up namespaces in the same assembly - so, say for instance you defined a struct in say MyProject.Structs and in MyProject.Classes.Test you're typing away and want to use one of the structs in MyProject.Structs, it'd be very useful if the macro could look in there too (or am I missing something and it already does it??)

  • Umm...ignore me, I see it already tries that...however for me at least (using VS.NET 2003) it fails - seems to get stuck in a specific Assembly and get nowhere else so doesn't find the correct NameSpace

  • Hi Jan,



    Other enhancements I have added in my version is to wrap the process in an Undo context, so a single undo will change everything back.



    simply add this before your changes:

    Dim CloseUndoContext As Boolean = False

    If DTE.UndoContext.IsOpen = False Then

    CloseUndoContext = True

    DTE.UndoContext.Open("TypeFinderAddDirectiveMacro", False)

    End If



    and add this after your changes:

    If CloseUndoContext Then DTE.UndoContext.Close()



    Another change I made was to check for the "Option" statement (VB only) and make sure the Imports statement was after that. With the changes that now check for existing namespaces that might not be needed, but worth looking into.



    Keep up the great work.

  • Oh man. What a neat macro. (All four) thumbs up.

  • I am having the same issues as Scott... this macro just hangs for me saying it's searching assembly xyz. Cool idea though.

Comments have been disabled for this content.