Skip to content

Commit 71b9268

Browse files
committed
Address review feedback
1 parent 77efb55 commit 71b9268

3 files changed

Lines changed: 23 additions & 21 deletions

File tree

src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ private sealed partial class Emitter
2323
private const string CtorParamInitMethodNameSuffix = "CtorParamInit";
2424
private const string DefaultOptionsStaticVarName = "s_defaultOptions";
2525
private const string DefaultContextBackingStaticVarName = "s_defaultContext";
26+
private const string ElementInfoPropName = "ElementInfo";
2627
internal const string GetConverterFromFactoryMethodName = "GetConverterFromFactory";
2728
private const string InfoVarName = "info";
2829
private const string JsonSerializerContextName = "JsonSerializerContext";
2930
internal const string JsonContextVarName = "jsonContext";
31+
private const string KeyInfoPropName = "KeyInfo";
3032
private const string NumberHandlingPropName = "NumberHandling";
3133
private const string ObjectCreatorPropName = "ObjectCreator";
3234
private const string OptionsInstanceVariableName = "Options";
@@ -510,8 +512,8 @@ private string GenerateForCollection(TypeGenerationSpec typeGenerationSpec)
510512
string metadataInitSource = @$"{JsonCollectionInfoValuesTypeRef}<{typeRef}> {InfoVarName} = new {JsonCollectionInfoValuesTypeRef}<{typeRef}>()
511513
{{
512514
{ObjectCreatorPropName} = {objectCreatorValue},
513-
KeyInfo = {keyTypeMetadataPropertyName!},
514-
ElementInfo = {valueTypeMetadataPropertyName},
515+
{KeyInfoPropName} = {keyTypeMetadataPropertyName!},
516+
{ElementInfoPropName} = {valueTypeMetadataPropertyName},
515517
{NumberHandlingPropName} = {numberHandlingArg},
516518
{SerializeHandlerPropName} = {serializeHandlerValue}
517519
}};

src/libraries/System.Text.Json/ref/System.Text.Json.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public static partial class JsonSerializer
240240
public static TValue? Deserialize<TValue>(this System.Text.Json.Nodes.JsonNode? node, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
241241
public static TValue? Deserialize<TValue>(this System.Text.Json.Nodes.JsonNode? node, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo) { throw null; }
242242
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
243-
public static TValue? Deserialize<TValue>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
243+
public static TValue? Deserialize< TValue>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
244244
public static TValue? Deserialize<TValue>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo) { throw null; }
245245
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
246246
public static void Serialize(System.IO.Stream utf8Json, object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { }
@@ -322,7 +322,7 @@ public JsonSerializerOptions(System.Text.Json.JsonSerializerOptions options) { }
322322
public System.Text.Json.Serialization.JsonUnknownTypeHandling UnknownTypeHandling { get { throw null; } set { } }
323323
public bool WriteIndented { get { throw null; } set { } }
324324
public void AddContext<TContext>() where TContext : System.Text.Json.Serialization.JsonSerializerContext, new() { }
325-
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Getting a converter for a type may require reflection which depends on unreferenced code.")]
325+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Getting a converter for a type may require reflection which depends on unreferenced code.")]
326326
public System.Text.Json.Serialization.JsonConverter GetConverter(System.Type typeToConvert) { throw null; }
327327
}
328328
public enum JsonTokenType : byte
@@ -509,9 +509,9 @@ public void WritePropertyName(System.ReadOnlySpan<byte> utf8PropertyName) { }
509509
public void WritePropertyName(System.ReadOnlySpan<char> propertyName) { }
510510
public void WritePropertyName(string propertyName) { }
511511
public void WritePropertyName(System.Text.Json.JsonEncodedText propertyName) { }
512+
public void WriteRawValue(string json, bool skipInputValidation = false) { }
512513
public void WriteRawValue(System.ReadOnlySpan<byte> utf8Json, bool skipInputValidation = false) { }
513514
public void WriteRawValue(System.ReadOnlySpan<char> json, bool skipInputValidation = false) { }
514-
public void WriteRawValue(string json, bool skipInputValidation = false) { }
515515
public void WriteStartArray() { }
516516
public void WriteStartArray(System.ReadOnlySpan<byte> utf8PropertyName) { }
517517
public void WriteStartArray(System.ReadOnlySpan<char> propertyName) { }
@@ -760,9 +760,9 @@ public abstract partial class JsonValue : System.Text.Json.Nodes.JsonNode
760760
public static System.Text.Json.Nodes.JsonValue Create(uint value, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; }
761761
[System.CLSCompliantAttribute(false)]
762762
public static System.Text.Json.Nodes.JsonValue Create(ulong value, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; }
763+
public static System.Text.Json.Nodes.JsonValue? Create<T>(T? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> jsonTypeInfo, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; }
763764
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed. Use the overload that takes a JsonTypeInfo, or make sure all of the required types are preserved.")]
764765
public static System.Text.Json.Nodes.JsonValue? Create<T>(T? value, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; }
765-
public static System.Text.Json.Nodes.JsonValue? Create<T>(T? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> jsonTypeInfo, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; }
766766
public abstract bool TryGetValue<T>([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out T? value);
767767
}
768768
}
@@ -798,7 +798,7 @@ public abstract partial class JsonConverter
798798
internal JsonConverter() { }
799799
public abstract bool CanConvert(System.Type typeToConvert);
800800
}
801-
[System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Enum | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Property | System.AttributeTargets.Struct, AllowMultiple=false)]
801+
[System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Enum | System.AttributeTargets.Field | System.AttributeTargets.Property | System.AttributeTargets.Struct, AllowMultiple = false)]
802802
public partial class JsonConverterAttribute : System.Text.Json.Serialization.JsonAttribute
803803
{
804804
protected JsonConverterAttribute() { }
@@ -875,7 +875,7 @@ public sealed partial class JsonPropertyNameAttribute : System.Text.Json.Seriali
875875
public JsonPropertyNameAttribute(string name) { }
876876
public string Name { get { throw null; } }
877877
}
878-
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)]
878+
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = false)]
879879
public sealed partial class JsonPropertyOrderAttribute : System.Text.Json.Serialization.JsonAttribute
880880
{
881881
public JsonPropertyOrderAttribute(int order) { }
@@ -885,8 +885,8 @@ public JsonPropertyOrderAttribute(int order) { }
885885
public sealed partial class JsonSerializableAttribute : System.Text.Json.Serialization.JsonAttribute
886886
{
887887
public JsonSerializableAttribute(System.Type type) { }
888-
public System.Text.Json.Serialization.JsonSourceGenerationMode GenerationMode { get { throw null; } set { } }
889888
public string? TypeInfoPropertyName { get { throw null; } set { } }
889+
public System.Text.Json.Serialization.JsonSourceGenerationMode GenerationMode { get { throw null; } set { } }
890890
}
891891
public abstract partial class JsonSerializerContext
892892
{
@@ -895,24 +895,24 @@ protected JsonSerializerContext(System.Text.Json.JsonSerializerOptions? options)
895895
public System.Text.Json.JsonSerializerOptions Options { get { throw null; } }
896896
public abstract System.Text.Json.Serialization.Metadata.JsonTypeInfo? GetTypeInfo(System.Type type);
897897
}
898-
[System.FlagsAttribute]
899-
public enum JsonSourceGenerationMode
900-
{
901-
Default = 0,
902-
Metadata = 1,
903-
Serialization = 2,
904-
}
905898
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=false)]
906899
public sealed partial class JsonSourceGenerationOptionsAttribute : System.Text.Json.Serialization.JsonAttribute
907900
{
908901
public JsonSourceGenerationOptionsAttribute() { }
909902
public System.Text.Json.Serialization.JsonIgnoreCondition DefaultIgnoreCondition { get { throw null; } set { } }
910-
public System.Text.Json.Serialization.JsonSourceGenerationMode GenerationMode { get { throw null; } set { } }
911903
public bool IgnoreReadOnlyFields { get { throw null; } set { } }
912904
public bool IgnoreReadOnlyProperties { get { throw null; } set { } }
913905
public bool IncludeFields { get { throw null; } set { } }
914906
public System.Text.Json.Serialization.JsonKnownNamingPolicy PropertyNamingPolicy { get { throw null; } set { } }
915907
public bool WriteIndented { get { throw null; } set { } }
908+
public System.Text.Json.Serialization.JsonSourceGenerationMode GenerationMode { get { throw null; } set { } }
909+
}
910+
[System.FlagsAttribute]
911+
public enum JsonSourceGenerationMode
912+
{
913+
Default = 0,
914+
Metadata = 1,
915+
Serialization = 2,
916916
}
917917
public partial class JsonStringEnumConverter : System.Text.Json.Serialization.JsonConverterFactory
918918
{
@@ -1013,9 +1013,9 @@ public static partial class JsonMetadataServices
10131013
public static System.Text.Json.Serialization.Metadata.JsonTypeInfo<TCollection> CreateStackInfo<TCollection>(System.Text.Json.JsonSerializerOptions options, System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<TCollection> collectionInfo, System.Action<TCollection, object?> addFunc) where TCollection : System.Collections.IEnumerable { throw null; }
10141014
public static System.Text.Json.Serialization.Metadata.JsonTypeInfo<TCollection> CreateStackInfo<TCollection, TElement>(System.Text.Json.JsonSerializerOptions options, System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<TCollection> collectionInfo) where TCollection : System.Collections.Generic.Stack<TElement> { throw null; }
10151015
public static System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> CreateValueInfo<T>(System.Text.Json.JsonSerializerOptions options, System.Text.Json.Serialization.JsonConverter converter) { throw null; }
1016+
public static System.Text.Json.Serialization.JsonConverter<T> GetUnsupportedTypeConverter<T>() { throw null; }
10161017
public static System.Text.Json.Serialization.JsonConverter<T> GetEnumConverter<T>(System.Text.Json.JsonSerializerOptions options) where T : struct { throw null; }
10171018
public static System.Text.Json.Serialization.JsonConverter<T?> GetNullableConverter<T>(System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> underlyingTypeInfo) where T : struct { throw null; }
1018-
public static System.Text.Json.Serialization.JsonConverter<T> GetUnsupportedTypeConverter<T>() { throw null; }
10191019
}
10201020
public sealed partial class JsonObjectInfoValues<T>
10211021
{

src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonMetadataServices.Converters.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public static partial class JsonMetadataServices
179179
/// Creates a <see cref="JsonConverter{T}"/> instance that throws <see cref="NotSupportedException"/>.
180180
/// </summary>
181181
/// <typeparam name="T">The generic definition for the type.</typeparam>
182-
/// <returns></returns>
182+
/// <returns>A <see cref="JsonConverter{T}"/> instance that throws <see cref="NotSupportedException"/></returns>
183183
public static JsonConverter<T> GetUnsupportedTypeConverter<T>()
184184
=> new UnsupportedTypeConverter<T>();
185185

@@ -188,7 +188,7 @@ public static JsonConverter<T> GetUnsupportedTypeConverter<T>()
188188
/// </summary>
189189
/// <typeparam name="T">The generic definition for the enum type.</typeparam>
190190
/// <param name="options">The <see cref="JsonSerializerOptions"/> to use for serialization and deserialization.</param>
191-
/// <returns></returns>
191+
/// <returns>A <see cref="JsonConverter{T}"/> instance that converts <typeparamref name="T"/> values.</returns>
192192
public static JsonConverter<T> GetEnumConverter<T>(JsonSerializerOptions options) where T : struct, Enum
193193
=> new EnumConverter<T>(EnumConverterOptions.AllowNumbers, options ?? throw new ArgumentNullException(nameof(options)));
194194

@@ -197,7 +197,7 @@ public static JsonConverter<T> GetEnumConverter<T>(JsonSerializerOptions options
197197
/// </summary>
198198
/// <typeparam name="T">The generic definition for the underlying nullable type.</typeparam>
199199
/// <param name="underlyingTypeInfo">Serialization metadata for the underlying nullable type.</param>
200-
/// <returns></returns>
200+
/// <returns>A <see cref="JsonConverter{T}"/> instance that converts <typeparamref name="T?"/> values</returns>
201201
public static JsonConverter<T?> GetNullableConverter<T>(JsonTypeInfo<T> underlyingTypeInfo) where T : struct
202202
{
203203
if (underlyingTypeInfo == null)

0 commit comments

Comments
 (0)