Вопрос

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
Это было полезно?

Решение

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

Другие советы

It is not recommended to use same name for namespaces and classes.

In this case I'll name the namespace as Resources notice this is plural since namespaces provide logical grouping of types.

Class name should be more specific. What does Resource tells you? Um, nothing. Name your classes properly, class name should communicate what it does. In other words it should be self explanatory. Without knowing much about what that Recource is I can't come up with a good name.

@Habib got it right with good links so am out of choices to provide you some useful links.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top