diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonProperty.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonProperty.cs index 84675bc0b4e36b..ef120f791f0858 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonProperty.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonProperty.cs @@ -16,7 +16,6 @@ public readonly struct JsonProperty /// The value of this property. /// public JsonElement Value { get; } - private string? _name { get; } internal JsonProperty(JsonElement value) { @@ -25,8 +24,9 @@ internal JsonProperty(JsonElement value) /// /// The name of this property. + /// This allocates a new string instance for each call. /// - public string Name => _name ?? Value.GetPropertyName(); + public string Name => Value.GetPropertyName(); /// /// Compares to the name of this property. @@ -116,15 +116,7 @@ public void WriteTo(Utf8JsonWriter writer) { ArgumentNullException.ThrowIfNull(writer); - if (_name is null) - { - Value.WritePropertyNameTo(writer); - } - else - { - writer.WritePropertyName(_name); - } - + Value.WritePropertyNameTo(writer); Value.WriteTo(writer); }