The naming convention for constants in C# is Pascal casing:
private const int TheAnswer = 42;
But sometimes we need to represent already-existing constants from the Windows API.
For example, I don’t know how to name this:
/// <summary>
/// With this style turned on for your form,
/// Windows double-buffers the form and all its child controls.
/// </summary>
public const int WS_EX_COMPOSITED = 0x02000000;
What should I name it?
Keeping it as WS_EX_COMPOSITED allows me to quickly associate it with the WinAPI, but it’s wrong.
Some options:
WsExComposited— Too hungarianComposited— Too shortWsExenum withCompositedin it — Still hungarianExtendedWindowsStyles.Composited— Constant in a class? Enum?
It should be noted that the objectives for a good naming are:
- It must be readable.
- It must not trigger FxCop and StyleCop, even if that means hiding it from them.
WS_EX_COMPOSITED is perfectly fine for part that directly interfaces with Win API (or any other documented API for that matter). The portion that you want to expose should follow standard conventions – have separate public facade to call native functions with good method names (you’ll eventually forget what you’ve researched about particular combinations of flags, but good wrapper method name will at least let you use it).
The side benefit of keeping the name as close as possible to native API is that you can search for constant directly in the MSDN/other documentation and find answer immediately. It will be much harder if you rename it.