Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it recommended to suffix all C# enums with "Enum" to avoid naming conflicts?

This stackoverflow question has an interesting discussion on how to avoid giving enums and properties the same names so that you don't have code like this:

public SaveStatus SaveStatus { get; set; }

It seems the accepted answer suggested to use "State" for the enum and "Status" for the property:

public SaveStatus SaveState { get; set; }

But I think this is hard to read and not immediately clear what is what.

Since this enum naming problem is a constant issue, I am considering simply always suffixing my enums with "Enum" so I would have this:

public SaveStatusEnum SaveStatus { get; set; }

SaveStatus = SaveStatusEnum.Succeeded;

Does anyone do this? Happy with it? Solved this issue in another way?

like image 696
Edward Tanguay Avatar asked May 28 '09 12:05

Edward Tanguay


1 Answers

From the MSDN page for Property naming guidelines:

Consider creating a property with the same name as its underlying type. For example, if you declare a property named Color, the type of the property should likewise be Color.

I'd take that as a "no" :)

Edit:

If you dislike using the fully qualified name inside the class that declares the property, you can work around it:

using SaveStatusEnum = MyNamespace.SaveStatus;
...
SaveStatus = SaveStatusEnum.SomeValue;

That way you can keep the enum name without the suffix, and limit the naming oddity to just that one class. :)

like image 134
Rytmis Avatar answered Oct 23 '22 00:10

Rytmis