1- # C# Language Coding Standards
1+ ---
2+ name : C# Language
3+ description : Follow these standards when developing C# source code.
4+ globs : ["**/*.cs"]
5+ ---
26
3- This document defines DEMA Consulting standards for C# software development
4- within Continuous Compliance environments.
7+ # C# Language Development Standard
58
6- ## Literate Programming Style (MANDATORY)
9+ ## Required Standards
710
8- Write all C# code in literate style because regulatory environments require
9- code that can be independently verified against requirements by reviewers.
11+ Read these standards first before applying this standard:
1012
11- - ** Intent Comments** : Start every code paragraph with a comment explaining
12- intent (not mechanics). Enables verification that code matches requirements.
13- - ** Logical Separation** : Use blank lines to separate logical code paragraphs.
14- Makes algorithm structure visible to reviewers.
15- - ** Purpose Over Process** : Comments describe why, code shows how. Separates
16- business logic from implementation details.
17- - ** Standalone Clarity** : Reading comments alone should explain the algorithm
18- approach. Supports independent code review.
13+ - ** ` coding-principles.md ` ** - Universal coding principles and quality gates
1914
20- ### Example
15+ # File Patterns
16+
17+ - ** Source Files** : ` **/*.cs `
18+
19+ # Literate Coding Example
2120
2221``` csharp
2322// Validate input parameters to prevent downstream errors
@@ -36,51 +35,13 @@ var validatedResults = BusinessRuleEngine.ValidateAndProcess(processedData);
3635return OutputFormatter .Format (validatedResults );
3736```
3837
39- ## XML Documentation (MANDATORY)
40-
41- Document ALL members (public, internal, private) with XML comments because
42- compliance documentation is auto-generated from source code comments and review
43- agents need to validate implementation against documented intent.
44-
45- ## Dependency Management
46-
47- Structure code for testability because all functionality must be validated
48- through automated tests linked to requirements.
49-
50- ### Rules
51-
52- - ** Inject Dependencies** : Use constructor injection for all external dependencies.
53- Enables mocking for unit tests.
54- - ** Avoid Static Dependencies** : Use dependency injection instead of static
55- calls. Makes code testable in isolation.
56- - ** Single Responsibility** : Each class should have one reason to change.
57- Simplifies testing and requirements traceability.
58- - ** Pure Functions** : Minimize side effects and hidden state. Makes behavior
59- predictable and testable.
60-
61- ## Error Handling
62-
63- Implement comprehensive error handling because failures must be logged for
64- audit trails and compliance reporting.
65-
66- - ** Validate Inputs** : Check all parameters and throw appropriate exceptions
67- with clear messages
68- - ** Use Typed Exceptions** : Throw specific exception types
69- (` ArgumentException ` , ` InvalidOperationException ` ) for different error
70- conditions
71- - ** Include Context** : Exception messages should include enough information
72- for troubleshooting
73- - ** Log Appropriately** : Use structured logging for audit trails in regulated
74- environments
38+ # Code Formatting
7539
76- ## Quality Checks
40+ - ** Format entire solution** : ` dotnet format `
41+ - ** Format specific project** : ` dotnet format MyProject.csproj `
42+ - ** Format specific file** : ` dotnet format --include MyFile.cs `
7743
78- Before submitting C# code, verify:
44+ # Quality Checks
7945
80- - [ ] Code follows Literate Programming Style rules (intent comments, logical separation)
81- - [ ] XML documentation on ALL members with required tags
82- - [ ] Dependencies injected via constructor (no static dependencies)
83- - [ ] Single responsibility principle followed (one reason to change)
84- - [ ] Input validation with typed exceptions and clear messages
85- - [ ] Zero compiler warnings with ` TreatWarningsAsErrors=true `
86- - [ ] Compatible with ReqStream requirements traceability
46+ - [ ] Zero compiler warnings (` TreatWarningsAsErrors=true ` )
47+ - [ ] XmlDoc documentation complete on all members (public, internal, protected, private)
0 commit comments