dotnet-csharp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesedotnet-csharp
dotnet-csharp
Overview
概述
C# language patterns, coding standards, and .NET runtime features for idiomatic, performant code. This consolidated skill spans 25 topic areas. Load the appropriate companion file from based on the routing table below.
references/本技能提供符合.NET规范且高性能的C#语言模式、编码标准及.NET运行时特性。整合后的技能涵盖25个主题领域。请根据下方的路由表,从目录加载对应的配套文件。
references/Always-Load Baseline
始终加载的基础内容
These references define correctness and quality standards that apply to all C# code — load them by default whenever producing or reviewing code, regardless of what the user asked for:
- — naming conventions, file layout, style rules
references/coding-standards.md - — async/await correctness, ConfigureAwait, cancellation propagation (nearly all .NET code uses async)
references/async-patterns.md - — SOLID, DRY, single responsibility, dependency inversion, anti-pattern detection
references/solid-principles.md - — common mistakes the agent should avoid without being told (async void, DI lifetime misuse, swallowed exceptions)
references/code-smells.md - — .NET 10/11 and C# 14/15 features, version matrix, TFM-specific code generation rules (compensates for training data cutoff)
references/dotnet-releases.md
以下参考文档定义了适用于所有C#代码的正确性和质量标准——无论用户需求如何,在生成或评审代码时都应默认加载:
- — 命名规范、文件布局、样式规则
references/coding-standards.md - — async/await正确性、ConfigureAwait、取消操作传播(几乎所有.NET代码都会使用async)
references/async-patterns.md - — SOLID、DRY、单一职责、依赖倒置、反模式检测
references/solid-principles.md - — 无需告知即可避免的常见错误(async void、DI生命周期误用、异常被吞)
references/code-smells.md - — .NET 10/11和C# 14/15特性、版本矩阵、针对目标框架(TFM)的代码生成规则(弥补训练数据截止后的内容)
references/dotnet-releases.md
On-Demand References
按需加载的参考内容
Load these when the topic matches (see Routing Table keywords):
当主题匹配时加载以下内容(参见路由表中的关键词):
Routing Table
路由表
| Topic | Keywords | Description | Companion File |
|---|---|---|---|
| Coding standards | naming, file layout, style rules | Baseline C# conventions (naming, layout, style rules) | references/coding-standards.md |
| Async/await | async, Task, ConfigureAwait, cancellation | async/await, Task patterns, ConfigureAwait, cancellation | references/async-patterns.md |
| Dependency injection | DI, services, scopes, keyed, lifetimes | MS DI, keyed services, scopes, decoration, lifetimes | references/dependency-injection.md |
| Configuration | Options pattern, user secrets, feature flags | Options pattern, user secrets, feature flags, IOptions<T> | references/configuration.md |
| Source generators | IIncrementalGenerator, GeneratedRegex, LoggerMessage | IIncrementalGenerator, GeneratedRegex, LoggerMessage, STJ | references/source-generators.md |
| Nullable reference types | annotations, migration, agent mistakes | Annotation strategies, migration, agent mistakes | references/nullable-reference-types.md |
| Serialization | System.Text.Json, Protobuf, MessagePack, AOT | System.Text.Json source generators, Protobuf, MessagePack | references/serialization.md |
| Channels | Channel<T>, bounded/unbounded, backpressure | Channel<T>, bounded/unbounded, backpressure, drain | references/channels.md |
| LINQ optimization | IQueryable vs IEnumerable, compiled queries | IQueryable vs IEnumerable, compiled queries, allocations | references/linq-optimization.md |
| Domain modeling | aggregates, value objects, domain events | Aggregates, value objects, domain events, repositories | references/domain-modeling.md |
| SOLID principles | SRP, DRY, anti-patterns, compliance checks | SOLID and DRY principles, C# anti-patterns, fixes | references/solid-principles.md |
| Concurrency | lock, SemaphoreSlim, Interlocked, concurrent collections | lock, SemaphoreSlim, Interlocked, concurrent collections | references/concurrency-patterns.md |
| Roslyn analyzers | DiagnosticAnalyzer, CodeFixProvider, multi-version | DiagnosticAnalyzer, CodeFixProvider, CodeRefactoring | references/roslyn-analyzers.md |
| Editorconfig | IDE/CA severity, AnalysisLevel, globalconfig | IDE/CA severity, AnalysisLevel, globalconfig, enforcement | references/editorconfig.md |
| File I/O | FileStream, RandomAccess, FileSystemWatcher, paths | FileStream, RandomAccess, FileSystemWatcher, MemoryMappedFile | references/file-io.md |
| Native interop | P/Invoke, LibraryImport, ComWrappers, marshalling | P/Invoke, LibraryImport, ComWrappers, marshalling, cross-platform | references/native-interop.md |
| Input validation | .NET 10 AddValidation, FluentValidation | .NET 10 AddValidation, FluentValidation, ProblemDetails | references/input-validation.md |
| Validation patterns | DataAnnotations, IValidatableObject, IValidateOptions | DataAnnotations, IValidatableObject, IValidateOptions<T> | references/validation-patterns.md |
| Modern patterns | records, pattern matching, primary constructors | Records, pattern matching, primary constructors, C# 12-15 | references/modern-patterns.md |
| API design | naming, parameter ordering, return types, extensions | Naming, parameter ordering, return types, error patterns | references/api-design.md |
| Type design/perf | struct vs class, sealed, Span/Memory, collections | struct vs class, sealed, Span/Memory, collections | references/type-design-performance.md |
| Code smells | anti-patterns, async misuse, DI mistakes, fixes | Anti-patterns, async misuse, DI mistakes, fixes | references/code-smells.md |
| .NET releases | .NET 10, .NET 11, C# 14, C# 15, TFM, version, union, extension blocks, field keyword | Version matrix, new features, TFM-specific code generation | references/dotnet-releases.md |
| Globalization | CultureInfo, StringComparison, TimeZoneInfo, Rune, encoding | Culture-aware coding, string comparison, time zones, character processing | references/globalization.md |
| WASM interop | JSImport, JSExport, standalone WASM, wasm-experimental, browser | JSImport/JSExport, standalone .NET WASM, browser APIs, WASM AOT | references/wasm-interop.md |
| 主题 | 关键词 | 描述 | 配套文件 |
|---|---|---|---|
| 编码标准 | naming, file layout, style rules | 基础C#约定(命名、布局、样式规则) | references/coding-standards.md |
| Async/await | async, Task, ConfigureAwait, cancellation | async/await、Task模式、ConfigureAwait、取消操作 | references/async-patterns.md |
| 依赖注入 | DI, services, scopes, keyed, lifetimes | MS DI、键控服务、作用域、装饰器、生命周期 | references/dependency-injection.md |
| 配置 | Options pattern, user secrets, feature flags | Options模式、用户机密、功能标志、IOptions<T> | references/configuration.md |
| 源代码生成器 | IIncrementalGenerator, GeneratedRegex, LoggerMessage | IIncrementalGenerator、GeneratedRegex、LoggerMessage、STJ | references/source-generators.md |
| 可空引用类型 | annotations, migration, agent mistakes | 注解策略、迁移、常见错误 | references/nullable-reference-types.md |
| 序列化 | System.Text.Json, Protobuf, MessagePack, AOT | System.Text.Json源代码生成器、Protobuf、MessagePack | references/serialization.md |
| Channels | Channel<T>, bounded/unbounded, backpressure | Channel<T>、有界/无界、背压、排空 | references/channels.md |
| LINQ优化 | IQueryable vs IEnumerable, compiled queries | IQueryable与IEnumerable对比、编译查询、内存分配 | references/linq-optimization.md |
| 领域建模 | aggregates, value objects, domain events | 聚合根、值对象、领域事件、仓储 | references/domain-modeling.md |
| SOLID原则 | SRP, DRY, anti-patterns, compliance checks | SOLID和DRY原则、C#反模式、修复方案 | references/solid-principles.md |
| 并发 | lock, SemaphoreSlim, Interlocked, concurrent collections | lock、SemaphoreSlim、Interlocked、并发集合 | references/concurrency-patterns.md |
| Roslyn分析器 | DiagnosticAnalyzer, CodeFixProvider, multi-version | DiagnosticAnalyzer、CodeFixProvider、代码重构 | references/roslyn-analyzers.md |
| Editorconfig | IDE/CA severity, AnalysisLevel, globalconfig | IDE/CA规则级别、AnalysisLevel、全局配置、强制执行 | references/editorconfig.md |
| 文件I/O | FileStream, RandomAccess, FileSystemWatcher, paths | FileStream、RandomAccess、FileSystemWatcher、内存映射文件 | references/file-io.md |
| 原生互操作 | P/Invoke, LibraryImport, ComWrappers, marshalling | P/Invoke、LibraryImport、ComWrappers、封送处理、跨平台 | references/native-interop.md |
| 输入验证 | .NET 10 AddValidation, FluentValidation | .NET 10 AddValidation、FluentValidation、ProblemDetails | references/input-validation.md |
| 验证模式 | DataAnnotations, IValidatableObject, IValidateOptions | DataAnnotations、IValidatableObject、IValidateOptions<T> | references/validation-patterns.md |
| 现代模式 | records, pattern matching, primary constructors | Records、模式匹配、主构造函数、C# 12-15 | references/modern-patterns.md |
| API设计 | naming, parameter ordering, return types, extensions | 命名、参数顺序、返回类型、错误模式 | references/api-design.md |
| 类型设计/性能 | struct vs class, sealed, Span/Memory, collections | struct与class对比、密封类、Span/Memory、集合 | references/type-design-performance.md |
| 代码异味 | anti-patterns, async misuse, DI mistakes, fixes | 反模式、async误用、DI错误、修复方案 | references/code-smells.md |
| .NET版本 | .NET 10, .NET 11, C# 14, C# 15, TFM, version, union, extension blocks, field keyword | 版本矩阵、新特性、针对目标框架(TFM)的代码生成 | references/dotnet-releases.md |
| 全球化 | CultureInfo, StringComparison, TimeZoneInfo, Rune, encoding | 文化感知编码、字符串比较、时区、字符处理 | references/globalization.md |
| WASM互操作 | JSImport, JSExport, standalone WASM, wasm-experimental, browser | JSImport/JSExport、独立.NET WASM、浏览器API、WASM AOT | references/wasm-interop.md |
Scope
适用范围
- C# language features (C# 8-15)
- .NET runtime patterns (async, DI, config, serialization, channels, LINQ)
- Code quality (analyzers, editorconfig, code smells, SOLID)
- Type design and domain modeling
- File I/O and native interop
- Globalization (string comparison, CultureInfo, time zones, character processing, encoding)
- Input validation at the model level (DataAnnotations, IValidatableObject, FluentValidation, Options validation)
- C#语言特性(C# 8-15)
- .NET运行时模式(async、DI、配置、序列化、Channels、LINQ)
- 代码质量(分析器、editorconfig、代码异味、SOLID)
- 类型设计与领域建模
- 文件I/O与原生互操作
- 全球化(字符串比较、CultureInfo、时区、字符处理、编码)
- 模型级输入验证(DataAnnotations、IValidatableObject、FluentValidation、Options验证)
Out of scope
不适用范围
- ASP.NET Core / web API patterns (request-level validation, endpoint filters) -> [skill:dotnet-api]
- UI framework patterns -> [skill:dotnet-ui]
- Testing patterns -> [skill:dotnet-testing]
- Build/MSBuild/project setup -> [skill:dotnet-tooling]
- Performance profiling tools -> [skill:dotnet-tooling]
- ASP.NET Core / Web API模式(请求级验证、端点过滤器)-> [skill:dotnet-api]
- UI框架模式 -> [skill:dotnet-ui]
- 测试模式 -> [skill:dotnet-testing]
- 构建/MSBuild/项目设置 -> [skill:dotnet-tooling]
- 性能分析工具 -> [skill:dotnet-tooling]