C# Class Naming Conventions
Silly question but it's been a long time since I properly coded in C#, and I've forgotten my naming standards and run into a mental block, so to speak!
I have a reusable class that will be used by 50+ projects, and I want to give it a proper name. The namespace of the DLL is correct (e.g. Client.PROJECT/PRODUCT.xxx.yyy
).
I was thinking of naming the class as "Common" but was wondering if that was a lit开发者_如何学Pythontle too generic?
The class name should generally indicate the function of the class. "Common" is generally better as part of the name for a library (e.g. "Common.Logging" or "Ninject.Web.Common") to indicate that the files within that library are common to a particular purpose, and likely to be used by a number of other libraries.
You'll need to share more information about the purpose of the class you're creating if you want better ideas for what to call the class. But in general, it's good to think of the "consumer's" experience. For example, which makes more sense?
var common = new Common();
common.LogInfo("something happened");
... or:
var log = new LogService();
log.LogInfo("something happened");
Usually, I use "Shared" or Utils
for these kind of projects.
And generally, I do not add other namespaces to it, e.g. I prefer Utils
to MyProject.Utils
, Except when I modify Utils
to serve explicitly for that project, then I rename it to MyProject.Shared
or MyProject.Utils
.
Hope this helps.
精彩评论