Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 little too generic?

like image 732
user728584 Avatar asked Feb 25 '23 06:02

user728584


2 Answers

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");
like image 161
StriplingWarrior Avatar answered Feb 26 '23 19:02

StriplingWarrior


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.

like image 31
Kamyar Avatar answered Feb 26 '23 21:02

Kamyar