-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.JsonenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additions
Milestone
Description
Motivation
There's a substantial amount of duplication in the following code:
class MyPoco
{
[JsonIgnore(JsonIgnoreCondition.WhenWritingNull)]
public string? PropA { get; set; }
[JsonIgnore(JsonIgnoreCondition.WhenWritingNull)]
public string? PropB { get; set; }
[JsonIgnore(JsonIgnoreCondition.WhenWritingNull)]
public string? PropC { get; set; }
}that could be eliminated using a type-level declaration:
[JsonIgnore(JsonIgnoreCondition.WhenWritingNull)]
class MyPoco
{
public string? PropA { get; set; }
public string? PropB { get; set; }
public string? PropC { get; set; }
}API Proposal
namespace System.Text.Json.Serialization;
-[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
+[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public partial class JsonIgnoreAttribute;cc @stephentoub
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.JsonenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additions