简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM