Search code examples
c#.netnamespacessap-dotnet-connector

Is there a way to reference a certain class/interface/... by enclosing it with its namespace rather than a using directive "using namespace_name"?


Is there a way to reference a certain class/interface/... by enclosing it with its namespace rather than a using directive "using namespace_name" ?!

As, I'm working on a website, which uses SAP .NET connector. I already added a reference for connector ddl, and while referencing its namespace "using namespace_name", or set class namespace to another one rather than connector namespace,

I got error regarding connector classes with that error message "The type or namespace couldn't be found, are you missing a using directive or an assembly reference?".

But while changing namespace name to connector namespace, everything is going well?!

// Set namespace to be IDestinationConfiguration interface namespace.
// Using this, everything is going well.
namespace SAP.Middleware.Connector
{
    public class ConnectorConfiguration : IDestinationConfiguration
    {
    }
}

// Using that way; it's not working, and got an error regarding IDestinationConfiguration even it belongs to refernced namespace.
using SAP.Middleware.Connector;

public class ConnectorConfiguration : IDestinationConfiguration
{
}

So, connector types forced me to set namespace of class to their namespace!

Is this possible? If so, how?


Solution

  • Is this what you are after?

    public class ConnectorConfiguration: SAP.Middleware.Connection.IDestinationConfiguration
    {
    
    }
    

    You can write all your code without usings if you like, you just need to use the fully qualified namespace name for every class/interface where the using isn't used.

    If you try this:

    using SAPTEST = SAP.Middleware.Connection;
    namespace TestNamespace 
    {
       public class ConnectorConfiguration: SAPTEST.IDestinationConfiguration
       {
       }
    }
    

    If that works, but it doesn't work if you remove SAPTEST, then IDestinationConfiguration must be declared in another namespace too.