dotnet-csharp

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

dotnet-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
references/
based on the routing table below.
本技能提供符合.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:
  • references/coding-standards.md
    — naming conventions, file layout, style rules
  • references/async-patterns.md
    — async/await correctness, ConfigureAwait, cancellation propagation (nearly all .NET code uses async)
  • references/solid-principles.md
    — SOLID, DRY, single responsibility, dependency inversion, anti-pattern detection
  • references/code-smells.md
    — common mistakes the agent should avoid without being told (async void, DI lifetime misuse, swallowed exceptions)
  • references/dotnet-releases.md
    — .NET 10/11 and C# 14/15 features, version matrix, TFM-specific code generation rules (compensates for training data cutoff)
以下参考文档定义了适用于所有C#代码的正确性和质量标准——无论用户需求如何,在生成或评审代码时都应默认加载:
  • references/coding-standards.md
    — 命名规范、文件布局、样式规则
  • references/async-patterns.md
    — async/await正确性、ConfigureAwait、取消操作传播(几乎所有.NET代码都会使用async)
  • references/solid-principles.md
    — SOLID、DRY、单一职责、依赖倒置、反模式检测
  • references/code-smells.md
    — 无需告知即可避免的常见错误(async void、DI生命周期误用、异常被吞)
  • references/dotnet-releases.md
    — .NET 10/11和C# 14/15特性、版本矩阵、针对目标框架(TFM)的代码生成规则(弥补训练数据截止后的内容)

On-Demand References

按需加载的参考内容

Load these when the topic matches (see Routing Table keywords):
当主题匹配时加载以下内容(参见路由表中的关键词):

Routing Table

路由表

TopicKeywordsDescriptionCompanion File
Coding standardsnaming, file layout, style rulesBaseline C# conventions (naming, layout, style rules)references/coding-standards.md
Async/awaitasync, Task, ConfigureAwait, cancellationasync/await, Task patterns, ConfigureAwait, cancellationreferences/async-patterns.md
Dependency injectionDI, services, scopes, keyed, lifetimesMS DI, keyed services, scopes, decoration, lifetimesreferences/dependency-injection.md
ConfigurationOptions pattern, user secrets, feature flagsOptions pattern, user secrets, feature flags, IOptions<T>references/configuration.md
Source generatorsIIncrementalGenerator, GeneratedRegex, LoggerMessageIIncrementalGenerator, GeneratedRegex, LoggerMessage, STJreferences/source-generators.md
Nullable reference typesannotations, migration, agent mistakesAnnotation strategies, migration, agent mistakesreferences/nullable-reference-types.md
SerializationSystem.Text.Json, Protobuf, MessagePack, AOTSystem.Text.Json source generators, Protobuf, MessagePackreferences/serialization.md
ChannelsChannel<T>, bounded/unbounded, backpressureChannel<T>, bounded/unbounded, backpressure, drainreferences/channels.md
LINQ optimizationIQueryable vs IEnumerable, compiled queriesIQueryable vs IEnumerable, compiled queries, allocationsreferences/linq-optimization.md
Domain modelingaggregates, value objects, domain eventsAggregates, value objects, domain events, repositoriesreferences/domain-modeling.md
SOLID principlesSRP, DRY, anti-patterns, compliance checksSOLID and DRY principles, C# anti-patterns, fixesreferences/solid-principles.md
Concurrencylock, SemaphoreSlim, Interlocked, concurrent collectionslock, SemaphoreSlim, Interlocked, concurrent collectionsreferences/concurrency-patterns.md
Roslyn analyzersDiagnosticAnalyzer, CodeFixProvider, multi-versionDiagnosticAnalyzer, CodeFixProvider, CodeRefactoringreferences/roslyn-analyzers.md
EditorconfigIDE/CA severity, AnalysisLevel, globalconfigIDE/CA severity, AnalysisLevel, globalconfig, enforcementreferences/editorconfig.md
File I/OFileStream, RandomAccess, FileSystemWatcher, pathsFileStream, RandomAccess, FileSystemWatcher, MemoryMappedFilereferences/file-io.md
Native interopP/Invoke, LibraryImport, ComWrappers, marshallingP/Invoke, LibraryImport, ComWrappers, marshalling, cross-platformreferences/native-interop.md
Input validation.NET 10 AddValidation, FluentValidation.NET 10 AddValidation, FluentValidation, ProblemDetailsreferences/input-validation.md
Validation patternsDataAnnotations, IValidatableObject, IValidateOptionsDataAnnotations, IValidatableObject, IValidateOptions<T>references/validation-patterns.md
Modern patternsrecords, pattern matching, primary constructorsRecords, pattern matching, primary constructors, C# 12-15references/modern-patterns.md
API designnaming, parameter ordering, return types, extensionsNaming, parameter ordering, return types, error patternsreferences/api-design.md
Type design/perfstruct vs class, sealed, Span/Memory, collectionsstruct vs class, sealed, Span/Memory, collectionsreferences/type-design-performance.md
Code smellsanti-patterns, async misuse, DI mistakes, fixesAnti-patterns, async misuse, DI mistakes, fixesreferences/code-smells.md
.NET releases.NET 10, .NET 11, C# 14, C# 15, TFM, version, union, extension blocks, field keywordVersion matrix, new features, TFM-specific code generationreferences/dotnet-releases.md
GlobalizationCultureInfo, StringComparison, TimeZoneInfo, Rune, encodingCulture-aware coding, string comparison, time zones, character processingreferences/globalization.md
WASM interopJSImport, JSExport, standalone WASM, wasm-experimental, browserJSImport/JSExport, standalone .NET WASM, browser APIs, WASM AOTreferences/wasm-interop.md
主题关键词描述配套文件
编码标准naming, file layout, style rules基础C#约定(命名、布局、样式规则)references/coding-standards.md
Async/awaitasync, Task, ConfigureAwait, cancellationasync/await、Task模式、ConfigureAwait、取消操作references/async-patterns.md
依赖注入DI, services, scopes, keyed, lifetimesMS DI、键控服务、作用域、装饰器、生命周期references/dependency-injection.md
配置Options pattern, user secrets, feature flagsOptions模式、用户机密、功能标志、IOptions<T>references/configuration.md
源代码生成器IIncrementalGenerator, GeneratedRegex, LoggerMessageIIncrementalGenerator、GeneratedRegex、LoggerMessage、STJreferences/source-generators.md
可空引用类型annotations, migration, agent mistakes注解策略、迁移、常见错误references/nullable-reference-types.md
序列化System.Text.Json, Protobuf, MessagePack, AOTSystem.Text.Json源代码生成器、Protobuf、MessagePackreferences/serialization.md
ChannelsChannel<T>, bounded/unbounded, backpressureChannel<T>、有界/无界、背压、排空references/channels.md
LINQ优化IQueryable vs IEnumerable, compiled queriesIQueryable与IEnumerable对比、编译查询、内存分配references/linq-optimization.md
领域建模aggregates, value objects, domain events聚合根、值对象、领域事件、仓储references/domain-modeling.md
SOLID原则SRP, DRY, anti-patterns, compliance checksSOLID和DRY原则、C#反模式、修复方案references/solid-principles.md
并发lock, SemaphoreSlim, Interlocked, concurrent collectionslock、SemaphoreSlim、Interlocked、并发集合references/concurrency-patterns.md
Roslyn分析器DiagnosticAnalyzer, CodeFixProvider, multi-versionDiagnosticAnalyzer、CodeFixProvider、代码重构references/roslyn-analyzers.md
EditorconfigIDE/CA severity, AnalysisLevel, globalconfigIDE/CA规则级别、AnalysisLevel、全局配置、强制执行references/editorconfig.md
文件I/OFileStream, RandomAccess, FileSystemWatcher, pathsFileStream、RandomAccess、FileSystemWatcher、内存映射文件references/file-io.md
原生互操作P/Invoke, LibraryImport, ComWrappers, marshallingP/Invoke、LibraryImport、ComWrappers、封送处理、跨平台references/native-interop.md
输入验证.NET 10 AddValidation, FluentValidation.NET 10 AddValidation、FluentValidation、ProblemDetailsreferences/input-validation.md
验证模式DataAnnotations, IValidatableObject, IValidateOptionsDataAnnotations、IValidatableObject、IValidateOptions<T>references/validation-patterns.md
现代模式records, pattern matching, primary constructorsRecords、模式匹配、主构造函数、C# 12-15references/modern-patterns.md
API设计naming, parameter ordering, return types, extensions命名、参数顺序、返回类型、错误模式references/api-design.md
类型设计/性能struct vs class, sealed, Span/Memory, collectionsstruct与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, browserJSImport/JSExport、独立.NET WASM、浏览器API、WASM AOTreferences/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]