llasarov
llasarov

Reputation: 2111

Alias for imported namespace

I'm working on a project using StyleCop to verify the coding style. It forces me to write my code as follows:

using AF.Data.Oracle
{
   using Oracle.DataAccess.Client; // *** Compile error here ***

   class Foo {}
}

But I constantly get an error telling that type 'DataAccess' could not be found in namespace 'AF.Data.Oracle'.

I know that I can use aliases for every type from Oracle.DataAccess.Client, but this would add several alias definitions.

But is it possible to use something like alias for a namespace?

Upvotes: 0

Views: 338

Answers (1)

Oded
Oded

Reputation: 499012

Use the global namespace alias:

namespace AF.Data.Oracle
{
   using global::Oracle.DataAccess.Client; 

   class Foo {}
}

This will avoid the namespace clash between AF.Data.Oracle and any namespace beginning with Oracle by ensuring you mean the Oracle that is at the namespace root.

Upvotes: 4

Related Questions