Search code examples
c#namespacesresharperclassname

Namespace & Class name collide


What is the best practice when naming a class same as the end of a namespace?

Example:

    Successful.Domain.Resource {
    public class Resource {}
    }

    Successful.Data.Resource {
    public class Resources {}
    }

If i want to use the Resource class in the Successful.Data namespace, i can't just reference Resource as i want. I need to declare its namespace like Domain.Resource.Resource

I use Resharper and structure all my code in folders, that's wye i have the namespace like that, example of folder structure:

Successful.Domain (Namespace)

  • Resource (Folder)
    • Resource.cs
    • ResourceLocation.cs
    • ResourceSettings.cs

Successful.Data (Namespace)

  • Resource (Folder)
    • Resources.cs

Solution

  • See: Framework Design Guidelines - Names of Namespaces

    X DO NOT use the same name for a namespace and a type in that namespace.

    So it is recommend to use a different class name than your namespace.

    You may also see this article by Eric Lippert: Do not name a class the same as its namespace, Part One