system-text-json-net11
Ce qu’il fait
Cette compétence montre comment utiliser trois nouvelles fonctions JSON de .NET 11 : une option intégrée de nommage en PascalCase et des recherches typées d'informations de type JSON. Elle s'adresse aux développeurs sur .NET 11 qui travaillent avec JSON en C#.
Quand l’utiliser
- ✓Quand une application .NET 11 a besoin de noms de propriétés JSON en PascalCase sans écrire de logique de nommage personnalisée.
- ✓Quand du code appelle GetTypeInfo puis convertit le résultat en JsonTypeInfo typé.
- ✓Quand vous voulez vérifier qu'un type JSON est disponible sans entourer l'appel de try et catch.
Lien du skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet11/skills/system-text-json-net11/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Dans mon application .NET 11, sérialise mes modèles en JSON avec des noms de propriétés en PascalCase, sans code de nommage personnalisé.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
L'agent définit la politique de nommage PascalCase intégrée dans les options du sérialiseur, utilise les méthodes de recherche typées si nécessaire, puis exécute le code pour montrer le résultat.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis GitHub.
System.Text.Json — .NET 11
Three APIs were added to System.Text.Json in .NET 11. This skill tells you exactly
when to reach for each one, what to write, what not to write, and how to prove the
result runs. Do not describe these APIs to the user — apply them, then run the code and
show the output.
| API | Replaces the pre-.NET-11 workaround of... |
|---|---|
JsonNamingPolicy.PascalCase (static property) |
writing a custom JsonNamingPolicy subclass or hand-annotating every member with [JsonPropertyName] |
JsonSerializerOptions.GetTypeInfo<T>() |
calling non-generic GetTypeInfo(typeof(T)) and casting to JsonTypeInfo<T> |
JsonSerializerOptions.TryGetTypeInfo<T>(out JsonTypeInfo<T>? info) |
wrapping GetTypeInfo in try/catch to probe availability |
Step 0 — Make the requested net11.0 validation possible
These APIs only exist in the .NET 11 base class library. Before writing code:
- Run
dotnet --list-sdksand confirm an SDK that can targetnet11.0is present — an11.xSDK, or a later SDK with thenet11.0targeting pack. - If the user explicitly asks you to run the sample and no suitable SDK is installed,
use the official
dotnet-installscript to install the current .NET 11 SDK into a temporary or project-local directory. Prefer the GA channel build. Use a preview only when GA is not yet available or the user explicitly requested a preview. Do not require administrator access, change the machine-widePATH, or replace an installed SDK. - Run the sample with that local
dotnetexecutable. If download or execution is blocked, still provide the completenet11.0program and report that it was not run. Never substitutenet10.0, a custom naming policy, or a different API and present that as validation of the .NET 11 feature.
Use the channel, not a guessed version. Try the GA channel first:
$installScript = Join-Path $env:TEMP "dotnet-install-$([guid]::NewGuid()).ps1"
try {
Invoke-WebRequest -Uri 'https://dot.net/v1/dotnet-install.ps1' -OutFile $installScript
& $installScript -Channel 11.0 -InstallDir .\.dotnet
& .\.dotnet\dotnet.exe run --project <PATH_TO_NET11_PROJECT>
}
finally {
Remove-Item -LiteralPath $installScript -Force -ErrorAction SilentlyContinue
}
install_script="$(mktemp "${TMPDIR:-/tmp}/dotnet-install.XXXXXX")"
trap 'rm -f "$install_script"' EXIT
curl -fsSL https://dot.net/v1/dotnet-install.sh -o "$install_script"
bash "$install_script" --channel 11.0 --install-dir ./.dotnet
./.dotnet/dotnet run --project <PATH_TO_NET11_PROJECT>
Before .NET 11 GA, retry the install with -Quality preview (PowerShell) or
--quality preview (shell).
Decision table — symptom → do this → never do this
Match the user's request to a row, apply the Do this cell verbatim, and confirm the Verify column before you are done.
| User asks for… | Do this (on net11.0) |
Never do this | Verify |
|---|---|---|---|
| PascalCase JSON property names | options.PropertyNamingPolicy = JsonNamingPolicy.PascalCase; |
define class …: JsonNamingPolicy; add per-member [JsonPropertyName]; string-case the names yourself |
output JSON keys are PascalCase — e.g. "Name", "Age" |
| PascalCase dictionary keys | options.DictionaryKeyPolicy = JsonNamingPolicy.PascalCase; |
set only PropertyNamingPolicy; pre-transform the dictionary; define a custom policy |
dictionary keys such as pendingOrders become "PendingOrders" |
Strongly-typed metadata JsonTypeInfo<T> |
set TypeInfoResolver = new DefaultJsonTypeInfoResolver(), then JsonTypeInfo<T> ti = options.GetTypeInfo<T>(); |
(JsonTypeInfo<T>)options.GetTypeInfo(typeof(T)) |
variable is typed JsonTypeInfo<T>, no cast |
| Probe whether metadata is resolved | if (options.TryGetTypeInfo<T>(out var ti)) { … } else { … } |
try { options.GetTypeInfo<T>(); } catch (…) { … } |
no try/catch; both branches handled |
Rule 1 — PascalCase property names
When the user wants JSON output whose property names are PascalCase (Name, Age)
and asks for the built-in / framework-provided way:
- Create or reuse a
JsonSerializerOptionsand setPropertyNamingPolicy = JsonNamingPolicy.PascalCase. - Serialize with those options.
Do not write a JsonNamingPolicy subclass, do not add [JsonPropertyName("…")]
attributes to force casing, and do not upper-case the first letter of each name by
hand. `JsonNamingPolicy
Questions fréquentes
Fonctionne-t-elle sur .NET 10 ?
Non. Ces API n'existent que dans la bibliothèque de base de .NET 11.
Installera-t-elle un SDK plus récent ?
Si vous demandez d'exécuter l'exemple et qu'aucun SDK .NET 11 approprié n'est présent, elle peut en installer un.
À quoi sert la recherche try-get ?
Elle remplace le fait d'entourer la recherche de try et catch simplement pour vérifier qu'un type est disponible.
Détails
Description originale de l’auteur
Imperative guidance for the System.Text.Json APIs added in .NET 11: the built-in `JsonNamingPolicy.PascalCase` naming policy, and the strongly-typed generic `JsonSerializerOptions.GetTypeInfo` and `JsonSerializerOptions.TryGetTypeInfo` metadata accessors (generic overloads that return a typed `JsonTypeInfo`). USE ONLY when the user is targeting net11.0 or later and needs PascalCase JSON property or dictionary-key names without writing a custom naming policy, a strongly-typed generic `JsonTypeInfo` instead of the non-generic `JsonTypeInfo`, or a no-throw way to probe whether a type's serializat
repo: dotnet/skills
Popularité
- Étoiles GitHub
- 5.8k
- Position au classement
- #14656
- Licence
- MIT
- Mis à jour
- 02/11/2026
Commentaires
- …
Autres skills de ce dépôt
create-custom-agent
5.8kAide votre agent à créer des fichiers d'agents personnalisés pour VS Code, avec leurs propres outils, instructions et transferts vers d'autres agents.
create-skill
5.8kAide votre agent à créer une nouvelle skill d'agent avec un nom valide, une description de déclenchement claire et un fichier SKILL.md conforme à la norme.
csharp-scripts
5.8kAide votre agent à exécuter un petit programme C# en un seul fichier avec l'outil en ligne de commande .NET, sans créer de projet complet.
dotnet-pinvoke
5.8kAide votre agent à appeler correctement des bibliothèques natives C ou C++ depuis .NET, en couvrant les signatures, la gestion des chaînes, la mémoire et les handles sûrs.
Skills similaires
api-connector-builder
280kPermet à votre agent de créer de nouvelles connexions API en suivant le modèle existant. À utiliser pour ajouter une intégration sans inventer une nouvelle façon de faire.
api-design
280kAide votre agent à concevoir des API REST selon les bonnes pratiques. Utile pour définir la communication entre API, l'affichage des erreurs et l'organisation des données.
backend-patterns
280kAide votre agent avec les architectures côté serveur et l'optimisation des bases de données. Utile pour créer ou relire du code qui s'exécute sur le serveur.