Question

I am getting started on my first project experience with Visual Studio. My task is to use an existing Solution's source and expand its capabilities by adding new projects to said Solution.

My issue is that much of the existing source would be getting duplicated except for small changes. I am unfamiliar with with Visual Studio, so I don't know what time saving techniques are available to me.

In my mind it would be ideal if I could duplicate some of the existing classes and simply have renamed copies of them added to the project that I could edit without fudging up the parts of the project that are working.

I should add, the only reason I would need to go this far to duplicate mostly identical code, is because the naming conventions used on the earlier projects would be extremely misleading if I used them as dependancies in my own project.

Will Visual Studio maintain itself if I start changing namespaces of existing classes to something more generic so I can use them without making my code confusing for others to follow?

Is there an easy way in Visual Studio to duplicate an OLD class if my NEW class is going to have half the code be the same anyway?

Any advice on approach or convention is more than welcome. Incidentally, I am working in Visual Studio 2012 Pro. and the project is mostly coded in C# if that helps anyone.

Was it helpful?

Solution

Your question is vague, to get better answers you should put a concrete example of the problem you are facing.

Here are my ideas so far, they might give you a hint on what to do :

Example of the some of the hints described above :

using System;
using MyFamiliarNamespace = MyScaryNamespace;
using MyFamiliarClass = MyScaryNamespace.MyScaryClass;

namespace ConsoleApplication1
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var @class = new MyFamiliarClass();
            @class.HelloWorld();
        }
    }

    public static class MyScaryClassExtensions
    {
        public static void HelloWorld(this MyFamiliarClass myScaryClass)
        {
            Console.WriteLine("Hello world !");
        }
    }
}

// Consider this part being in another assembly
namespace MyScaryNamespace
{
    public class MyScaryClass
    {
    }
}
  • In my opinion you should not copy classes, while it seems the easiest thing to do it would sooner or later make things even more confusing, remember to Don't repeat yourself in programming.

  • Renaming namespaces : unless you have a tool like Resharper, doing it manually can be a real pain and prone to errors

  • Duplicating objects (or sort of) : if you absolutely have to duplicate objects then using something like Automapper can be a real-time saver in some situations.

Provide more details in your question so we can suggest better answers.

And giving a better title to it might be wise, too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top