ワンクリックで
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