csharp-naming-conventions
C# and .NET naming conventions, coding best practices, layout rules, unit testing, and Blazor component guidelines. Use when writing, reviewing, or refactoring C# / .NET / Blazor code or writing unit tests with xUnit and bUnit.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 4.9k
- Forks
- 494
01 前言 Front Matter
- name
- csharp-naming-conventions
- license
- MIT
- metadata
- { "author": "dvoituron", "version": "0.0.4" }
- description
- C# and .NET naming conventions, coding best practices, layout rules, unit testing, and Blazor component guidelines. Use when writing, reviewing, or refactoring C# / .NET / Blazor code or writing unit tests with xUnit and bUnit.
02 资源文件 28
- 参考文档metadata.json518 B
- 参考文档README.md2.6 KB
- 参考文档rules/_sections.md1.3 KB
- 参考文档rules/blazor-code.md1.2 KB
- 参考文档rules/blazor-components.md1.2 KB
- 参考文档rules/blazor-css.md2.8 KB
- 参考文档rules/blazor-javascript.md1.4 KB
- 参考文档rules/blazor-performance.md3.3 KB
- 参考文档rules/blazor-structure.md1.3 KB
- 参考文档rules/code-comments.md853 B
- 参考文档rules/code-conversion.md716 B
- 参考文档rules/code-datetime.md758 B
- 参考文档rules/code-exceptions.md1.1 KB
- 参考文档rules/code-if-pattern.md1.4 KB
- 参考文档rules/code-operators.md954 B
- 参考文档rules/code-static.md654 B
- 参考文档rules/code-strings.md1.6 KB
- 参考文档rules/code-using-namespace.md1.1 KB
- 参考文档rules/code-variables.md2.1 KB
- 参考文档rules/layout-formatting.md2.4 KB
- 参考文档rules/layout-members-order.md1003 B
- 参考文档rules/naming-async.md1.4 KB
- 参考文档rules/naming-casing.md3.0 KB
- 参考文档rules/naming-files.md1002 B
- 参考文档rules/naming-items.md845 B
- 参考文档rules/testing-blazor.md2.0 KB
- 参考文档rules/testing-coverage.md1.1 KB
- 参考文档rules/testing-practices.md2.6 KB
03 SKILL.md 正文
C# Naming Conventions and Best Practices
Comprehensive coding guidelines for .NET and C# developments, covering naming, layout, code patterns, unit testing, and Blazor conventions. Prioritized by impact to guide automated code generation and review.
When to Apply
Reference these guidelines when:
- Writing new C# / .NET code
- Reviewing or refactoring existing C# code
- Naming classes, methods, variables, properties, or parameters
- Formatting and laying out source files
- Working with async/await patterns
- Writing if/else, string, exception, or conversion logic
- Writing or reviewing unit tests (xUnit, bUnit)
- Building Blazor components and pages
- Organizing project file structures
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Naming & Casing | CRITICAL | naming- |
| 2 | Code Layout & Formatting | HIGH | layout- |
| 3 | Code Patterns | HIGH | code- |
| 4 | Unit Testing | HIGH | testing- |
| 5 | Blazor Conventions | MEDIUM-HIGH | blazor- |
Quick Reference
1. Naming & Casing (CRITICAL)
- naming-casing - Pascal case and Camel case conventions for all C# identifiers
- naming-files - File organization: one class per file, namespace matches folder
- naming-items - Explicit, unabbreviated, English-only names without prefixes
- naming-async - Postfix async methods with Async, eliding guidelines
2. Code Layout & Formatting (HIGH)
- layout-formatting - Indentation, braces, line length, and formatting rules
- layout-members-order - Member ordering within classes and no #region usage
3. Code Patterns (HIGH)
- code-variables - Variable declarations, var usage, access modifiers
- code-comments - Commenting conventions and XML documentation
- code-using-namespace - Using directives and file-scoped namespaces
- code-if-pattern - If braces, no-else-return, and guard pattern
- code-strings - String interpolation and StringBuilder usage
- code-exceptions - Exception handling and avoiding generic catches
- code-operators - Allowed and denied C# operators
- code-conversion - Data type conversion rules, never use ToString()
- code-datetime - DateTimeProvider for testable date/time code
- code-static - Avoid static classes except for extension methods
4. Unit Testing (HIGH)
- testing-practices - Seven best practices for unit tests
- testing-coverage - Code coverage with Coverlet and ReportGenerator
- testing-blazor - Blazor unit tests with bUnit and Verifier
5. Blazor Conventions (MEDIUM-HIGH)
- blazor-components - Component naming, routing, and file structure
- blazor-structure - Project folder organization with SOLID principles
- blazor-code - Methods, properties order, inject, and nullable defaults
- blazor-css - CSS isolation, root class and attribute selectors
- blazor-javascript - JavaScript interop and collocated JS files
- blazor-css - CSS isolation and ::deep pseudo-element usage
- blazor-performance - Rendering, cascading parameters, and optimization
How to Use
Use the linked rule files above for detailed explanations and code examples. Each rule file contains:
- Brief explanation of why it matters
- Correct code examples
- Incorrect patterns to avoid (when applicable)
- References to external guidelines
04 同仓库更多 Skills
Fluent UI Blazor v5 — Usage Guide
Provides accurate coding patterns for building Blazor applications with the Microsoft.FluentUI.AspNetCore.Components v5 NuGet package. Covers service registration, theming (CSS-based, no FluentDesignTheme), layout, navigation, dialogs, data grid, forms, icons, and common pitfalls.
update-dependencies
Update repository NuGet and NPM dependencies and lockfiles to the latest compatible versions, then validate library builds and bUnit tests. Use when asked to update or upgrade repository dependencies.