Question

Lets assume we have the following abstract base class that declares a parameterized method, whereas the parameter lives in another namespace:

using Example.SubNamespace;    
namespace Example
{
    public abstract class BaseClass
    {
        public abstract void Method(Parameter param);
    }
}

Following a simple class that acts as our parameter (note the different namespace):

namespace Example.SubNamespace
{
    public class Parameter
    {
    }
}

When implementing a sub class, visual studio offers the option "Implement Abstract Class" when right-clicking the derived class. I've done that in the following example:

namespace Example
{
    public class SubClass : BaseClass
    {
        public override void Method(SubNamespace.Parameter param)
        {
            throw new System.NotImplementedException();
        }
    }
}

Call me petty but sometimes it seems very annoying to me having the fully qualified namespaces within the methods signature.

Is there any possibility to implement an abstract class while automatically inserting the correct using directives? Changing these things manually seems like an unnecessary effort to me.

Was it helpful?

Solution

No way to do this. Consider placing your SubClass and BaseClass in the same namespace. I don't think this is a big deal.

You can also use intellisense to add namespaces:

Visual Studio keyboard shortcut to automatically add the needed 'using' statement

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