Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any guidance on enum suffix (Kind vs. Type)?

I am designing a .NET API for public use. In my API, there are a bunch of enums, and I'm struggling to decide on a convention to use for suffixes.

In the .NET framework, I see examples of using both "Kind" (e.g. System.DateTimeKind) as well as "Type" (e.g. System.IO.DriveType).

Looking at the public enums in mscorlib, I see that "Type" is used more often, but both are still used on some of the newer types, meaning it looks like Microsoft is not following any specific convention on this.

Does anyone have any recommendation about what to use in my API? Are there any published conventions out there covering this topic?

I'm leaning towards using "Kind" as the suffix, and reserving the term "Type" to deal with System.Type objects or data types.

like image 438
RobSiklos Avatar asked Jun 07 '13 17:06

RobSiklos


2 Answers

The only naming convention I know from Microsoft in relation to enumerations is this (from msdn)

  • Use Pascal case for Enum types and value names.
  • Use abbreviations sparingly.
  • Do not use an Enum suffix on Enum type names.
  • Use a singular name for most Enum types, but use a plural name for Enum types that are bit fields.
  • Always add the FlagsAttribute to a bit field Enum type.

It's quite old but don't see any update in relation to this.

I don't think anyone can tell you the "correct" approach for your specific question as both options are valid and it's just a matter of taste.

I'd say you should agree a common strategy with the team and stick with it. I think it's more important everyone to use the same naming convention than which one you use.

I personally use Type suffix, but again, it's just a matter of taste.

like image 161
Claudio Redi Avatar answered Oct 20 '22 10:10

Claudio Redi


Name your enums with descriptive noun phrases describing what the enum is (e.g., RegexOptions , DateTimeKind , BorderStyle, etc.). Don't force the use of arbitrary suffixes. The name should come naturally from what the thing is.

like image 20
Nicholas Carey Avatar answered Oct 20 '22 10:10

Nicholas Carey