用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/rudironsoni/Synaxis --skill dotnet-csharp-modern-patterns命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Routes .NET/C# work to domain skills. Loads coding-standards for code paths.
基于 SOC 职业分类
正在显示 SKILL.md
| name | dotnet-csharp-modern-patterns |
| description | Using records, pattern matching, primary constructors, collection expressions. C# 12-15 by TFM. |
| license | MIT |
| targets | ["*"] |
| category | fundamentals |
| subcategory | language-patterns |
| tags | ["csharp","dotnet","skill","language-patterns","records"] |
| version | 1.0.0 |
| author | dotnet-agent-harness |
| invocable | true |
| related_skills | ["dotnet-csharp-coding-standards","dotnet-csharp-async-patterns","dotnet-10-csharp-14"] |
| claudecode | {"allowed-tools":["Read","Grep","Glob","Bash","Write","Edit"]} |
| codexcli | {"short-description":".NET skill guidance for csharp tasks"} |
| opencode | {"allowed-tools":["Read","Grep","Glob","Bash","Write","Edit"]} |
| copilot | {} |
| geminicli | {} |
| antigravity | {} |
Modern C# language feature guidance adapted to the project's target framework. Always run [skill:dotnet-version-detection] first to determine TFM and C# version.
Cross-references: [skill:dotnet-csharp-coding-standards] for naming/style conventions, [skill:dotnet-csharp-async-patterns] for async-specific patterns.
| TFM | C# | Key Language Features |
|---|---|---|
| net8.0 | 12 | Primary constructors, collection expressions, alias any type |
| net9.0 | 13 | params collections, Lock type, partial properties |
| net10.0 | 14 | field keyword, extension blocks, nameof unbound generics |
| net11.0 | 15 (preview) | Collection expression with() arguments |
Use records for immutable data transfer objects, value semantics, and domain modeling where equality is based on values rather than identity.
// Positional record: concise, immutable, value equality
public record OrderSummary(int OrderId, decimal Total, DateOnly OrderDate);
// With additional members
public record Customer(string Name, Email)
{
DisplayName => ;
}
```text
```csharp
;
;
```text
| Use Case | Prefer |
| ------------------------------------ | ------------------------ |
| DTOs, API responses | `` |
| (, ) | ` ` |
| (, ) | `` |
| -, | ` ` |
| | `` (-) |
### -
```
= order { Total = order.Total + tax };
```csharp
---
Capture constructor parameters directly the / .
**** -- .
### ( )
```
( , <> )
{
{
logger.LogInformation(, id);
repo.GetByIdAsync(id);
}
}
```text
- Primary constructor parameters are **mutable** captures, `` fields. If immutability matters, assign to a
`` field the body.
- Do use primary constructors you need to validate parameters at construction time -- use a traditional
constructor guard clauses instead.
- For records, positional parameters become properties automatically. For classes/structs, they remain
captures.
```csharp
{
_connectionString = connectionString
?? ArgumentNullException((connectionString));
}
```text
---
Unified syntax creating collections `[...]`.
```csharp
[] numbers = [, , ];
List<> names = [, ];
ReadOnlySpan<> bytes = [, ];
[] combined = [..first, ..second, ];
List<> empty = [];
```text
Specify capacity, comparers, other constructor arguments:
```csharp
List<> nums = [(capacity: ), ..Generate()];
HashSet<> = [(comparer: StringComparer.OrdinalIgnoreCase), , ];
Dictionary<, > map = [(comparer: StringComparer.OrdinalIgnoreCase),
(, ), (, )];
```text
> **net11+ only.** Requires `<LangVersion>preview</LangVersion>`. Do use earlier TFMs.
---
``` => customer
{
{ Tier: , YearsActive: > } => ,
{ Tier: } => ,
{ Tier: } => ,
_ =>
};
```text
``` => data [> , .., > ];
=> values
{
[] => ,
[] => ,
[] =>
};
```text
``` => package
{
Letter { Weight: < } => m,
Parcel { Weight: w } w < => m + w * m,
Parcel { IsOversized: } => m,
_ => m
};
```text
---
Force callers to initialize properties at construction via initializers.
```csharp
{
Name { ; ; }
Email { ; ; }
? Phone { ; ; }
}
user = UserDto { Name = , Email = };
```
{
Reading
{
=> field;
=> field = >=
?
: ArgumentOutOfRangeException(());
}
}
```text
Replaces the manual pattern of declaring a field plus a property custom logic. Use you need validation
transformation a setter without a separate backing field.
> **net10+ only.** On earlier TFMs, use a traditional field.
---
Group extension members a type a single block.
```csharp
{
extension<T>(IEnumerable<T> source) T :
{
=> source.Where(x => x );
=> !source.Any();
}
}
```text
> **net10+ only.** On earlier TFMs, use traditional `` extension methods.
---
```csharp
Point = ( X, Y);
UserId = System.Guid;
Point origin = (, );
UserId id = UserId.NewGuid();
```text
Useful tuple aliases domain type aliases without creating a full type.
---
`` now supports additional collection types beyond arrays, including `Span<T>`, `ReadOnlySpan<T>`, types
implementing certain collection interfaces.
```
{
( msg messages)
Console.WriteLine(msg);
}
Log(, );
```text
> **net9+ only.** On net8, `` only supports arrays.
---
Use `System.Threading.Lock` instead of `` locking.
```csharp
Lock _lock = ();
{
(_lock)
{
}
}
```text
`Lock` provides a `Scope`-based API advanced scenarios more expressive than ` ()`.
> **net9+ only.** On net8, use ` _gate = ();` ` (_gate)`.
---
Partial properties enable source generators to define property signatures that users implement, vice versa.
```csharp
{
Name { ; ; }
}
{
_name = ;
Name
{
=> _name;
=> SetProperty( _name, );
}
}
```text
> **net9+ only.** See [skill:dotnet-csharp-source-generators] generator patterns.
---
```csharp
name = (List<>);
name2 = (Dictionary<,>);
```csharp
Useful logging, diagnostics, reflection scenarios.
> **net10+ only.**
---
When targeting multiple TFMs, newer language features may compile older targets. Use these approaches:
**PolySharp** -- Polyfills compiler- { => field; => field = Math.Max(, ); }
_value;
Value { => _value; => _value = Math.Max(, ); }
```text
See [skill:dotnet-multi-targeting] comprehensive polyfill guidance.
---
Feature guidance skill grounded publicly available language design rationale :
- **C
rationale relevant to skill: ; use
fields immutability needed. Source: https:
- **C
features. Source: https:
> **Note:** This skill applies publicly documented design rationale. It does represent speak the named
> sources.
**Primary approach:** Use Serena symbol operations efficient code navigation:
**Find definitions**: `serena_find_symbol` instead of text search
**Understand structure**: `serena_get_symbols_overview` organization
**Track references**: `serena_find_referencing_symbols` impact analysis
**Precise edits**: `serena_replace_symbol_body` clean modifications
**When to use Serena vs traditional tools:**
- ✅ **Use Serena**: Navigation, refactoring, dependency analysis, precise edits
- ✅ **Use Read/Grep**: Reading full files, pattern matching, simple text operations
- ✅ **Fallback**: If Serena unavailable, traditional tools work fine
**Example workflow:**
```text
Read: src/Services/OrderService.cs
Grep:
serena_find_symbol:
serena_get_symbols_overview:
```
- [C
- [Whats C
- [What