Search code examples
c#.netnaming-conventionsapi-design

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.


Solution

  • 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.