Drag-copying in Visual Studio Solution Explorer.

NOTE: I’ve tried this in Visual Studio 2008 (VS2k8), I’m assuming the same thing happens in Visual Studio 2005 (VS2k5).


In the process of refactoring, it’s *very* common for me to rename a type.  This is most easily done by renaming the file in the Solution Explorer (SE)–which renames the file, the type, and and any uses of the type in the entire solution.


Occasionally, I need to create a new type based on another.  Copying an abstract type in order to implement the abstract type is often handy–I just fill in the abstract members (and delete “abstract”) in the copied type after renaming it.


Drag-copy in the SE seems like it would take care of a couple of steps at once for me: make a copy and rename it.  Unfortunately it doesn’t do that.  It makes a copy of the file (as “Copy of typename.xx”) but doesn’t rename any types in the class that match the file name.


This might seem somewhat trivial… I can simply rename the file name then refactor rename the type in the file so that the type and all it’s constructors are renamed in one fell swoop.  Alas, this simply opens a can of worms that can completely confound a newcomer and annoy an expert.


That simple, intuitive method of renaming a copy of a file then the type within the file actually renames *all* types of that name.  Since we’ve just made a copy of the type, that means it’s always going rename types in two files.  The side-effect of drag-copy in SE means you *must* manually rename the type in the file you just copied.  You can do this with search-replace; but that’s friction I don’t want and really makes SE drag-copy unusable.


I’ve logged a bug about it on Connect; but the olde “by design” card was played…

2 thoughts on “Drag-copying in Visual Studio Solution Explorer.”

  1. If your goal is to create a concrete type inheriting from an abstract base type, the editors for both C# and VB.NET will fill in the necessary overrides for you. It seems to me like that would be a much easier way to go about it.

  2. @David. It’s six of one, half-a-dozen of the other, I suppose. Moot, if you consider the extra work involved with drag-copy.

    The alternative is I have to manually create a class and manually add the base class and have it implement the abstract members (via Shift-Alt-F10), then manually add the using directives (or go to each squiggle and manually automatically add the using directive), and implement the constructors (what I was looking for, IIRC, is to get most of the code from the constructors for free).

    With drag drop, I would have had to simply rename the class (getting all the c’tors renamed for free), delete the abstract members (and if their in a region, that’s a simple delete), derive from the abstract class and implement the abstract members (via Shift-Alt-F10).

    My real gripe is that drag-copy is not logical and adds friction with no value-added.

    In the future, I’ll simply use a Create Descendant refactoring…

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>