plugins/languages/csharp/skills/core/SKILL.md
C# 14 / .NET 10 LTS 核心开发规范。覆盖 nullable reference types、pattern matching、 primary constructors、collection expressions、params collections、field keyword、 ref struct interfaces、Roslyn analyzers 与 dotnet-format 配置。 当用户新建 .NET 项目、审查 C# 代码、配置 csproj、启用 nullable、调整 LangVersion, 或说 "C# 规范"、"现代 C#"、"C# 14"、".NET 10"、"nullable"、"primary constructor"、 "collection expression"、"dotnet format" 时加载, 是所有 C# skill 的基础依赖。
npx skillsauth add lazygophers/ccplugin csharp-coreInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
C# 14 + .NET 10 LTS 是当前主线 (LTS 至 2028-11)。任何 C# 文件改动必须先比对本规范。
新项目 .csproj 必须显式声明:
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisLevel>latest-all</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
仓库根放 .editorconfig + Directory.Build.props, 统一 LangVersion 与分析等级。
PascalCase 类型/方法/属性/常量; camelCase 局部变量与参数; 私有字段 _camelCaseAsync 结尾, 同时暴露 CancellationTokennamespace Foo;| 特性 | 用法 | 取代 |
|------|------|------|
| Primary constructors | public class Svc(IDb db) | 显式构造器 + 字段赋值 |
| Collection expressions | int[] x = [1, 2, 3]; | new int[] {1,2,3} |
| Spread | int[] all = [..a, ..b]; | Concat + ToArray |
| Params collections | void F(params ReadOnlySpan<int> xs) | params int[] 堆分配 |
| field keyword | get; set => field = value?.Trim(); | 显式 backing field |
| Ref struct interfaces | ref struct Buf : IDisposable | 无 |
| Escape \e | "\e[31mred" | "\x1b[31mred" |
| required 成员 | public required string Name { get; init; } | 构造器强制 |
| Lock 类型 | private readonly Lock _gate = new(); | lock(object) |
| using 别名任意类型 | using Point = (int X, int Y); | 无 |
#nullable disable; 例外需 PR 注释说明?; 内部不靠 ! (null-forgiving) 兜底NullReferenceException; 从源头消除ArgumentNullException.ThrowIfNull(x) 优于手写判空优先 switch expression + property pattern:
public decimal Discount(Customer c) => c switch
{
{ Tier: "vip", Age: > 60 } => 0.3m,
{ Tier: "vip" } => 0.2m,
{ Orders.Count: > 10 } => 0.1m,
_ => 0m
};
record / record struct + initwith 表达式产生副本IReadOnlyList<T> / ImmutableArray<T> 暴露IOptions<T> 管理配置; ILogger<T> 结构化日志[FromKeyedServices("k")]bool TryX(out) / 结果类型catch (Exception) 后无日志)Exception, 提供三个标准构造器<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.*" />
<PackageReference Include="Roslynator.Analyzers" Version="4.*" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.*" PrivateAssets="all" />
CI 强制:
dotnet format --verify-no-changes --severity warn
dotnet build /warnaserror
<IsAotCompatible>true</IsAotCompatible>Activator.CreateInstance(string) 反射构造泛型; 用 source generatorSystem.Text.Json source generator (JsonSerializerContext).Result / .Wait() (详见 csharp-async)async void 除 event handler 外一律禁止INotifyPropertyChanged 模板 (用 CommunityToolkit.Mvvm)development
Go 数据库规范——GORM Model 命名 ModelXxx、表名单数、枚举 uint8 + 常量、索引 idx_ 前缀 + deleted_at leading column、禁 time.Time 统一 int64 unix、禁指针/nullable 字段、TEXT/BLOB/JSON 禁 default、AutoMigrate 禁改主键。设计 DB model、写 GORM tag、建索引、做 migration 审查时触发。
development
Go HTTP API 规范——响应始终 200 + body code 字段、路由 /api/* 全 POST 单段 <Action><Model>、中间件逐路由注册禁 Group(prefix,mw...)、handler 仅返回 (rsp,error)、认证走 header。设计 HTTP API、写路由/handler/中间件时触发。
development
Go 项目结构规范——三层架构(API → Impl → State)、全局状态模式、internal/ 私有包、cmd/ 仅 main.go、go.work 多模块、禁止 Repository 接口和 DI 容器、struct 公共字段开头全 omitempty、handler var rsp 顶声明、禁 legacy migration。设计项目骨架、新建目录、组织包、做架构评审时触发。
development
Go 命名规范——Id/Uid 字段(非 ID)、IsActive/HasMFA 布尔前缀、CreatedAt 时间字段、接收者统一用 p、包名全小写无下划线、泛型类型参数描述性命名、集合字段 xxx_list 禁 xxxs 复数、Enum 0 值 XxxNil 禁 Unknown、禁 Status 统一 State、Set/Update 语义区分。定义结构体字段、函数、变量、包、接收者名、泛型、枚举时触发。