一键导入
dotnet-json-polymorphic
Configures polymorphic JSON serialization with [JsonPolymorphic] and [JsonDerivedType] attributes
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Configures polymorphic JSON serialization with [JsonPolymorphic] and [JsonDerivedType] attributes
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Analyzes and configures a .NET project or solution for Native AOT compatibility. Orchestrates source generator skills and applies AOT settings.
Converts a .NET solution to use Central Package Management (CPM). Use when the user wants to centralize, consolidate, or unify NuGet package versions across projects.
Enables tab autocomplete for the dotnet CLI. Use when the user wants to set up shell completion for dotnet commands.
Enables the Microsoft Testing Platform runner in global.json. Use when the user wants to enable or migrate to the new .NET testing platform.
Configures System.Text.Json source generation for AOT-compatible JSON serialization
Converts logging to use the LoggerMessage source generator for high-performance, AOT-compatible logging. Use when the user wants to optimize logging or organize log messages.
| name | dotnet-json-polymorphic |
| description | Configures polymorphic JSON serialization with [JsonPolymorphic] and [JsonDerivedType] attributes |
| license | MIT |
| metadata | {"author":"Im5tu","version":"1.0","repositoryUrl":"https://github.com/im5tu/dotnet-skills"} |
| allowed-tools | Bash(dotnet:*) Read Glob Grep AskUserQuestion |
Configure polymorphic JSON serialization using [JsonPolymorphic] and [JsonDerivedType] attributes for type-safe inheritance hierarchies.
TypeNameHandling with modern attributesAsk scope:
Search for existing [JsonPolymorphic] attributes:
TypeDiscriminatorPropertyName values foundExtract discriminator conventions:
TypeDiscriminatorPropertyName in existing attributesFind polymorphic candidates:
Ask about discriminator property name:
$type, Found: [list existing])"Check for consistency:
Apply attributes to base types:
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[JsonDerivedType(typeof(DerivedA), typeDiscriminator: "DerivedA")]
[JsonDerivedType(typeof(DerivedB), typeDiscriminator: "DerivedB")]
public abstract class BaseClass
{
}
"WeatherForecastWithCity")Add using directive:
using System.Text.Json.Serialization; is presentVerify with build:
dotnet build
Report results:
Before:
public abstract class Notification
{
public string Message { get; set; }
}
public class EmailNotification : Notification
{
public string EmailAddress { get; set; }
}
public class SmsNotification : Notification
{
public string PhoneNumber { get; set; }
}
After:
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[JsonDerivedType(typeof(EmailNotification), typeDiscriminator: "EmailNotification")]
[JsonDerivedType(typeof(SmsNotification), typeDiscriminator: "SmsNotification")]
public abstract class Notification
{
public string Message { get; set; }
}
public class EmailNotification : Notification
{
public string EmailAddress { get; set; }
}
public class SmsNotification : Notification
{
public string PhoneNumber { get; set; }
}
JSON Output:
{
"$type": "EmailNotification",
"message": "Hello",
"emailAddress": "user@example.com"
}
JsonSerializer.Serialize<Notification>(emailNotification))[JsonPolymorphic] attribute if it has derived types[JsonPolymorphic] when they define the contract for serialization