This project follows Microsoft C# Coding Conventions with some project-specific guidelines.
- Use 4 spaces for indentation (no tabs)
- Use LF line endings (Unix-style)
- Include a final newline at the end of files
- Remove trailing whitespace
These settings are enforced via .editorconfig.
Place opening braces on a new line (Allman style):
// Correct
public void Method()
{
if (condition)
{
DoSomething();
}
}
// Incorrect
public void Method() {
if (condition) {
DoSomething();
}
}- Aim for lines under 120 characters
- Break long method chains or parameter lists
| Element | Convention | Example |
|---|---|---|
| Namespace | PascalCase | kleversdk.provider |
| Class | PascalCase | KleverProvider |
| Interface | IPascalCase | IKleverProvider |
| Method | PascalCase | GetAccount() |
| Property | PascalCase | Balance |
| Public field | PascalCase | MaxRetries |
| Private field | _camelCase | _httpClient |
| Parameter | camelCase | accountAddress |
| Local variable | camelCase | transactionResult |
| Constant | PascalCase | DefaultTimeout |
- Place
usingstatements at the top of the file - Sort
Systemnamespaces first - Group related namespaces together
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using kleversdk.core;
using kleversdk.provider.Dto;Organize class members in this order:
- Constants
- Private fields
- Constructors
- Public properties
- Public methods
- Private methods
Add XML documentation for public APIs:
/// <summary>
/// Retrieves account information from the blockchain.
/// </summary>
/// <param name="address">The bech32 encoded address.</param>
/// <returns>Account details including balance and nonce.</returns>
/// <exception cref="ApiException">Thrown when the API request fails.</exception>
public async Task<AccountDto> GetAccount(string address)- Use comments to explain "why", not "what"
- Keep comments up to date with code changes
- Avoid obvious comments
- Use
async/awaitfor I/O operations - Suffix async methods with
Async(optional but recommended for new code) - Avoid
.Resultor.Wait()on tasks
// Correct
var account = await provider.GetAccount(address);
// Avoid
var account = provider.GetAccount(address).Result;- Use null-conditional operators where appropriate
- Validate parameters in public methods
public void Process(string input)
{
if (string.IsNullOrEmpty(input))
throw new ArgumentException("Input cannot be null or empty", nameof(input));
}- Use specific exception types
- Include meaningful error messages
- Don't catch exceptions you can't handle
The .editorconfig file will automatically configure your IDE. Ensure your editor respects EditorConfig files.
Rider supports .editorconfig out of the box. Enable "Format on Save" for automatic formatting.