简体   繁体   中英

Naming the Namespace

I am having an issue trying to figure out how to appropriately name my namespace. My namespace is currently:

<CompanyName>.<ProductName>.Configuration

However, using "Configuration" conflicts with:

System.Configuration

To make matters worse, I also have a class called ConfigurationManager. I know I could change it to something like:

<CompanyName>.<ProductName>.<ProductName>Configuration

but that seems redundant. Any ideas?

EDIT: Also, I'm aware when calling either class I can fully qualify the calling code but the frequency that the classes in the System.Configuration namespace and <CompanyName>.<ProductName>.Configuration namespace will be used would make for ugly code.

EDIT2: Providing specifics:

Using statements:

using System.Configuration;
using SummitConfiguration = SST.Summit.Configuration;

Problem Line Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);

Error Message 'SST.Summit.Configuration' is a 'namespace' but it is used like a 'type' (for problem line above)

Typically, in cases like this, I leave the Configuration namespace, and use an alias for accessing my namespace (instead of fully qualifying). For example:

using System.Configuration;
using PC = MyCompany.MyProduct.Configuration;

// ...

string configValue = PC.ConfigurationManager.GetValue("Foo");

What about doing something like this:

using System.Configuration;
using MyCompany.MyProduct.ProdConfig

or

using System.Configuration;
using MyCompany.MyProduct.Config

There shouldn't be a problem with using a namespace of Configuration - you'll just need to explicitly refer to the one you want by fully qualifying the name. It's a bit of a pain but I think a clear naming convention is better than coming up with a different name if the objects in your namespace really deal with configuration. As others have suggested, you can use aliases as well.

This may not work for you, but when I run into this, I just rename my namespace and/or class. Something like Config.ConfigManager.

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