C# Coding Standard

C# coding standard for Cadtastic Solutions.

View the Project on GitHub Cadtastic-Solutions/C-Sharp-Coding-Standard

Documentation Standards

Purpose

Documentation is a critical part of software development that serves multiple essential purposes:

Knowledge Transfer

Code Maintenance

Quality Assurance

Documentation Types

1. Code Documentation

XML Documentation Comments

Required for:

/// <summary>
/// Processes customer orders and updates inventory.
/// </summary>
/// <param name="order">The order to process. Must not be null.</param>
/// <param name="options">Optional processing configurations.</param>
/// <returns>The processed order with updated status.</returns>
/// <exception cref="ArgumentNullException">Thrown when order is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when inventory is insufficient.</exception>
public async Task<Order> ProcessOrderAsync(
    Order order, 
    ProcessingOptions? options = null)
{
    // Implementation
}

Inline Comments

Use for:

// Retry pattern with exponential backoff
for (int i = 1; i <= maxRetries; i++)
{
    try
    {
        await ProcessAsync();
        break;
    }
    catch (Exception) when (i < maxRetries)
    {
        // Wait longer between each retry
        await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, i)));
    }
}

2. Project Documentation (/docs)

index.md

# Project Name Documentation

Welcome to the Project Name documentation. This documentation will help you:
- Understand the project's architecture and design
- Set up your development environment
- Implement new features
- Troubleshoot common issues

## Quick Links
- [Getting Started](getting-started/installation.md)
- [Architecture Overview](guides/architecture.md)
- [API Documentation](api/endpoints.md)
- [Contributing Guidelines](CONTRIBUTING.md)

Installation Guide (getting-started/installation.md)

# Installation Guide

## Prerequisites
- .NET 6.0 SDK or higher
- Visual Studio 2022
- SQL Server 2019+

## Setup Steps
1. Clone the repository
2. Configure application settings
3. Run database migrations
4. Build and run the application

## Verification
Follow these steps to verify your installation...

3. API Documentation

Swagger/OpenAPI

Required for all Web API projects:

/// <summary>
/// Creates a new customer order.
/// </summary>
/// <remarks>
/// Sample request:
/// 
///     POST /api/orders
///     {
///        "customerId": "123",
///        "items": [
///           {
///              "productId": "456",
///              "quantity": 1
///           }
///        ]
///     }
/// </remarks>
/// <response code="201">Returns the newly created order</response>
/// <response code="400">If the order is invalid</response>
[ProducesResponseType(typeof(Order), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> CreateOrder([FromBody] CreateOrderRequest request)

Documentation Standards By File Type

1. README.md

# Project Name

Brief description of the project's purpose and main features.

## Quick Start
```bash
git clone [repository-url]
cd project-name
dotnet restore
dotnet run

Features

Documentation

Full documentation can be found in the docs folder.

Contributing

Please read our Contributing Guidelines.


### 2. CHANGELOG.md
```markdown
# Changelog

## [1.0.0] - 2024-03-20
### Added
- Feature X
- Feature Y

### Changed
- Updated dependency A to version 2.0
- Improved performance of operation B

### Fixed
- Bug in feature C
- Issue with component D

3. CONTRIBUTING.md

# Contributing Guidelines

## Development Process
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Submit a pull request

## Code Style
- Follow the project's coding standards
- Write unit tests for new features
- Update documentation as needed

## Pull Request Process
1. Update the README.md if needed
2. Update the CHANGELOG.md
3. Get approval from maintainers

Documentation Best Practices

Do's

Don'ts

Tools and Automation

Required Tools

Visual Studio Settings

<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
  <NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

Build Integration

# Documentation build steps
steps:
  - name: Build Documentation
    run: docfx build
  - name: Validate Links
    run: linkcheck

Review Process

Documentation Review Checklist

Additional Resources