The following style guide is mostly to help keep myself consistent.
- Options classes should have a static
Default
property that returns an instance configured with default options. - Options classes should always appear last in the parameter list, unless an
ILogger
parameter is also present. - Prefer options classes over enums.
- If the
Create
method does not take any arguments, inherit fromIFactory<T>
.
- Treat
null
strings the same asString.Empty
where possible rather than throwing an exception.
- If an extension method does more than just remapping arguments, consider adding it to a utility class (with the
Utilities
suffix). This enhances discoverability and allows the method to be used without importing other extension methods into the current scope.
- Properties should be associated with states, and methods should be associated with actions. For example,
OptionEnabled
should be a property, butEnableOption
should be a method.
- If the class provides required configuration details, use the
Configuration
suffix. - If the class provides optional configuration details, use the
Options
suffix. - Boolean options should use the
Enabled
suffix (e.g.OptionEnabled
).
- If there is a need for multiple
Create
methods, use methods with theFrom
prefix instead (FromStream
,FromFile
,FromBitmap
, etc.). For methods taking astring
argument, useParse
.
The following rules are consistent with .NET's capitalization conventions.
Use | Not |
---|---|
FileName |
Filename |
Id |
ID |
Ok |
OK |
UserName |
Username |
WhiteSpace |
Whitespace |