< Summary

Line coverage
9%
Covered lines: 31
Uncovered lines: 301
Coverable lines: 332
Total lines: 1118
Line coverage: 9.3%
Branch coverage
52%
Covered branches: 62
Total branches: 118
Branch coverage: 52.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
File 1: CreateArrayInfo(...)100%110%
File 1: CreateListInfo(...)100%110%
File 1: CreateDictionaryInfo(...)100%110%
File 1: CreateImmutableDictionaryInfo(...)100%110%
File 1: CreateIDictionaryInfo(...)100%110%
File 1: CreateIReadOnlyDictionaryInfo(...)100%110%
File 1: CreateImmutableEnumerableInfo(...)100%110%
File 1: CreateIListInfo(...)100%110%
File 1: CreateISetInfo(...)100%110%
File 1: CreateIReadOnlySetInfo(...)100%110%
File 1: CreateICollectionInfo(...)100%110%
File 1: CreateStackInfo(...)100%110%
File 1: CreateQueueInfo(...)100%110%
File 1: CreateConcurrentStackInfo(...)100%110%
File 1: CreateConcurrentQueueInfo(...)100%110%
File 1: CreateIEnumerableInfo(...)100%110%
File 1: CreateIAsyncEnumerableInfo(...)100%110%
File 1: CreateStackInfo(...)100%110%
File 1: CreateQueueInfo(...)100%110%
File 1: CreateStackOrQueueInfo(...)100%110%
File 1: CreateMemoryInfo(...)100%110%
File 1: CreateReadOnlyMemoryInfo(...)100%110%
File 2: GetUnsupportedTypeConverter()100%110%
File 2: GetEnumConverter(...)100%110%
File 2: GetNullableConverter(...)100%110%
File 2: GetNullableConverter(...)100%110%
File 2: GetTypedConverter(...)0%220%
File 3: CreatePropertyInfo(...)0%880%
File 3: CreateObjectInfo(...)100%110%
File 3: CreateValueInfo(...)100%110%
File 4: CreateCore(...)100%110%
File 4: CreateCore(...)0%440%
File 4: CreateCore(...)0%220%
File 4: GetConverter(...)0%440%
File 4: PopulateParameterInfoValues(...)0%440%
File 4: PopulateProperties(...)0%14140%
File 4: CreatePropertyInfoCore(...)0%440%
File 4: DeterminePropertyName(...)0%660%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Metadata\JsonMetadataServices.Collections.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections;
 5using System.Collections.Concurrent;
 6using System.Collections.Generic;
 7using System.Text.Json.Serialization.Converters;
 8
 9namespace System.Text.Json.Serialization.Metadata
 10{
 11    public static partial class JsonMetadataServices
 12    {
 13        /// <summary>
 14        /// Creates serialization metadata for an array.
 15        /// </summary>
 16        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 17        /// <param name="options">The <see cref="JsonSerializerOptions"/> to use.</param>
 18        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 19        /// <returns>Serialization metadata for the given type.</returns>
 20        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 21        public static JsonTypeInfo<TElement[]> CreateArrayInfo<TElement>(JsonSerializerOptions options, JsonCollectionIn
 022            => CreateCore(
 023                options,
 024                collectionInfo,
 025                new ArrayConverter<TElement[], TElement>());
 26
 27        /// <summary>
 28        /// Creates serialization metadata for types assignable to <see cref="List{T}"/>.
 29        /// </summary>
 30        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 31        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 32        /// <param name="options">The <see cref="JsonSerializerOptions"/> to use.</param>
 33        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 34        /// <returns>Serialization metadata for the given type.</returns>
 35        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 36        public static JsonTypeInfo<TCollection> CreateListInfo<TCollection, TElement>(
 37            JsonSerializerOptions options,
 38            JsonCollectionInfoValues<TCollection> collectionInfo)
 39            where TCollection : List<TElement>
 040            => CreateCore(
 041                options,
 042                collectionInfo,
 043                new ListOfTConverter<TCollection, TElement>());
 44
 45        /// <summary>
 46        /// Creates serialization metadata for types assignable to <see cref="Dictionary{TKey, TValue}"/>.
 47        /// </summary>
 48        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 49        /// <typeparam name="TKey">The generic definition of the key type.</typeparam>
 50        /// <typeparam name="TValue">The generic definition of the value type.</typeparam>
 51        /// <param name="options"></param>
 52        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 53        /// <returns>Serialization metadata for the given type.</returns>
 54        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 55        public static JsonTypeInfo<TCollection> CreateDictionaryInfo<TCollection, TKey, TValue>(
 56            JsonSerializerOptions options,
 57            JsonCollectionInfoValues<TCollection> collectionInfo)
 58            where TCollection : Dictionary<TKey, TValue>
 59            where TKey : notnull
 060            => CreateCore(
 061                options,
 062                collectionInfo,
 063                new DictionaryOfTKeyTValueConverter<TCollection, TKey, TValue>());
 64
 65
 66#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved
 67        /// <summary>
 68        /// Creates serialization metadata for <see cref="System.Collections.Immutable.ImmutableDictionary{TKey, TValue}
 69        /// types assignable to <see cref="System.Collections.Immutable.IImmutableDictionary{TKey, TValue}"/>.
 70        /// </summary>
 71        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 72        /// <typeparam name="TKey">The generic definition of the key type.</typeparam>
 73        /// <typeparam name="TValue">The generic definition of the value type.</typeparam>
 74        /// <param name="options"></param>
 75        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 76        /// <param name="createRangeFunc">A method to create an immutable dictionary instance.</param>
 77        /// <returns>Serialization metadata for the given type.</returns>
 78        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 79#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved
 80        public static JsonTypeInfo<TCollection> CreateImmutableDictionaryInfo<TCollection, TKey, TValue>(
 81            JsonSerializerOptions options,
 82            JsonCollectionInfoValues<TCollection> collectionInfo,
 83            Func<IEnumerable<KeyValuePair<TKey, TValue>>, TCollection> createRangeFunc)
 84            where TCollection : IReadOnlyDictionary<TKey, TValue>
 85            where TKey : notnull
 086        {
 087            ArgumentNullException.ThrowIfNull(createRangeFunc);
 88
 089            return CreateCore(
 090                options,
 091                collectionInfo,
 092                new ImmutableDictionaryOfTKeyTValueConverter<TCollection, TKey, TValue>(),
 093                createObjectWithArgs: createRangeFunc);
 094        }
 95
 96        /// <summary>
 97        /// Creates serialization metadata for types assignable to <see cref="IDictionary{TKey, TValue}"/>.
 98        /// </summary>
 99        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 100        /// <typeparam name="TKey">The generic definition of the key type.</typeparam>
 101        /// <typeparam name="TValue">The generic definition of the value type.</typeparam>
 102        /// <param name="options"></param>
 103        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 104        /// <returns>Serialization metadata for the given type.</returns>
 105        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 106        public static JsonTypeInfo<TCollection> CreateIDictionaryInfo<TCollection, TKey, TValue>(
 107            JsonSerializerOptions options,
 108            JsonCollectionInfoValues<TCollection> collectionInfo)
 109            where TCollection : IDictionary<TKey, TValue>
 110            where TKey : notnull
 0111            => CreateCore(
 0112                options,
 0113                collectionInfo,
 0114                new IDictionaryOfTKeyTValueConverter<TCollection, TKey, TValue>());
 115
 116        /// <summary>
 117        /// Creates serialization metadata for types assignable to <see cref="IReadOnlyDictionary{TKey, TValue}"/>.
 118        /// </summary>
 119        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 120        /// <typeparam name="TKey">The generic definition of the key type.</typeparam>
 121        /// <typeparam name="TValue">The generic definition of the value type.</typeparam>
 122        /// <param name="options"></param>
 123        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 124        /// <returns>Serialization metadata for the given type.</returns>
 125        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 126        public static JsonTypeInfo<TCollection> CreateIReadOnlyDictionaryInfo<TCollection, TKey, TValue>(
 127            JsonSerializerOptions options,
 128            JsonCollectionInfoValues<TCollection> collectionInfo)
 129            where TCollection : IReadOnlyDictionary<TKey, TValue>
 130            where TKey : notnull
 0131            => CreateCore(
 0132                options,
 0133                collectionInfo,
 0134                new IReadOnlyDictionaryOfTKeyTValueConverter<TCollection, TKey, TValue>());
 135
 136        /// <summary>
 137        /// Creates serialization metadata for non-dictionary immutable collection types.
 138        /// </summary>
 139        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 140        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 141        /// <param name="options"></param>
 142        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 143        /// <param name="createRangeFunc">A method to create an immutable dictionary instance.</param>
 144        /// <returns>Serialization metadata for the given type.</returns>
 145        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 146        public static JsonTypeInfo<TCollection> CreateImmutableEnumerableInfo<TCollection, TElement>(
 147            JsonSerializerOptions options,
 148            JsonCollectionInfoValues<TCollection> collectionInfo,
 149            Func<IEnumerable<TElement>, TCollection> createRangeFunc)
 150            where TCollection : IEnumerable<TElement>
 0151        {
 0152            ArgumentNullException.ThrowIfNull(createRangeFunc);
 153
 0154            return CreateCore(
 0155                options,
 0156                collectionInfo,
 0157                new ImmutableEnumerableOfTConverter<TCollection, TElement>(),
 0158                createObjectWithArgs: createRangeFunc);
 0159        }
 160
 161        /// <summary>
 162        /// Creates serialization metadata for types assignable to <see cref="IList"/>.
 163        /// </summary>
 164        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 165        /// <param name="options"></param>
 166        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 167        /// <returns>Serialization metadata for the given type.</returns>
 168        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 169        public static JsonTypeInfo<TCollection> CreateIListInfo<TCollection>(
 170            JsonSerializerOptions options,
 171            JsonCollectionInfoValues<TCollection> collectionInfo)
 172            where TCollection : IList
 0173            => CreateCore(
 0174                options,
 0175                collectionInfo,
 0176                new IListConverter<TCollection>());
 177
 178        /// <summary>
 179        /// Creates serialization metadata for types assignable to <see cref="IList{T}"/>.
 180        /// </summary>
 181        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 182        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 183        /// <param name="options"></param>
 184        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 185        /// <returns>Serialization metadata for the given type.</returns>
 186        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 187        public static JsonTypeInfo<TCollection> CreateIListInfo<TCollection, TElement>(
 188            JsonSerializerOptions options,
 189            JsonCollectionInfoValues<TCollection> collectionInfo)
 190            where TCollection : IList<TElement>
 0191            => CreateCore(
 0192                options,
 0193                collectionInfo,
 0194                new IListOfTConverter<TCollection, TElement>());
 195
 196        /// <summary>
 197        /// Creates serialization metadata for types assignable to <see cref="ISet{T}"/>.
 198        /// </summary>
 199        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 200        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 201        /// <param name="options"></param>
 202        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 203        /// <returns>Serialization metadata for the given type.</returns>
 204        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 205        public static JsonTypeInfo<TCollection> CreateISetInfo<TCollection, TElement>(
 206            JsonSerializerOptions options,
 207            JsonCollectionInfoValues<TCollection> collectionInfo)
 208            where TCollection : ISet<TElement>
 0209            => CreateCore(
 0210                options,
 0211                collectionInfo,
 0212                new ISetOfTConverter<TCollection, TElement>());
 213
 214#if NET
 215        /// <summary>
 216        /// Creates serialization metadata for types assignable to <see cref="IReadOnlySet{T}"/>.
 217        /// </summary>
 218        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 219        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 220        /// <param name="options"></param>
 221        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 222        /// <returns>Serialization metadata for the given type.</returns>
 223        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 224        public static JsonTypeInfo<TCollection> CreateIReadOnlySetInfo<TCollection, TElement>(
 225            JsonSerializerOptions options,
 226            JsonCollectionInfoValues<TCollection> collectionInfo)
 227            where TCollection : IReadOnlySet<TElement>
 0228            => CreateCore(
 0229                options,
 0230                collectionInfo,
 0231                new IReadOnlySetOfTConverter<TCollection, TElement>());
 232#endif
 233
 234        /// <summary>
 235        /// Creates serialization metadata for types assignable to <see cref="ICollection{T}"/>.
 236        /// </summary>
 237        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 238        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 239        /// <param name="options"></param>
 240        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 241        /// <returns>Serialization metadata for the given type.</returns>
 242        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 243        public static JsonTypeInfo<TCollection> CreateICollectionInfo<TCollection, TElement>(
 244            JsonSerializerOptions options,
 245            JsonCollectionInfoValues<TCollection> collectionInfo)
 246            where TCollection : ICollection<TElement>
 0247            => CreateCore(
 0248                options,
 0249                collectionInfo,
 0250                new ICollectionOfTConverter<TCollection, TElement>());
 251
 252        /// <summary>
 253        /// Creates serialization metadata for types assignable to <see cref="Stack{T}"/>.
 254        /// </summary>
 255        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 256        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 257        /// <param name="options"></param>
 258        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 259        /// <returns>Serialization metadata for the given type.</returns>
 260        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 261        public static JsonTypeInfo<TCollection> CreateStackInfo<TCollection, TElement>(
 262            JsonSerializerOptions options,
 263            JsonCollectionInfoValues<TCollection> collectionInfo)
 264            where TCollection : Stack<TElement>
 0265            => CreateCore(
 0266                options,
 0267                collectionInfo,
 0268                new StackOfTConverter<TCollection, TElement>());
 269
 270        /// <summary>
 271        /// Creates serialization metadata for types assignable to <see cref="Queue{T}"/>.
 272        /// </summary>
 273        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 274        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 275        /// <param name="options"></param>
 276        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 277        /// <returns>Serialization metadata for the given type.</returns>
 278        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 279        public static JsonTypeInfo<TCollection> CreateQueueInfo<TCollection, TElement>(
 280            JsonSerializerOptions options,
 281            JsonCollectionInfoValues<TCollection> collectionInfo)
 282            where TCollection : Queue<TElement>
 0283            => CreateCore(
 0284                options,
 0285                collectionInfo,
 0286                new QueueOfTConverter<TCollection, TElement>());
 287
 288        /// <summary>
 289        /// Creates serialization metadata for types assignable to <see cref="ConcurrentStack{T}"/>.
 290        /// </summary>
 291        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 292        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 293        /// <param name="options"></param>
 294        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 295        /// <returns>Serialization metadata for the given type.</returns>
 296        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 297        public static JsonTypeInfo<TCollection> CreateConcurrentStackInfo<TCollection, TElement>(
 298            JsonSerializerOptions options,
 299            JsonCollectionInfoValues<TCollection> collectionInfo)
 300            where TCollection : ConcurrentStack<TElement>
 0301            => CreateCore(
 0302                options,
 0303                collectionInfo,
 0304                new ConcurrentStackOfTConverter<TCollection, TElement>());
 305
 306        /// <summary>
 307        /// Creates serialization metadata for types assignable to <see cref="Queue{T}"/>.
 308        /// </summary>
 309        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 310        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 311        /// <param name="options"></param>
 312        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 313        /// <returns>Serialization metadata for the given type.</returns>
 314        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 315        public static JsonTypeInfo<TCollection> CreateConcurrentQueueInfo<TCollection, TElement>(
 316            JsonSerializerOptions options,
 317            JsonCollectionInfoValues<TCollection> collectionInfo)
 318            where TCollection : ConcurrentQueue<TElement>
 0319            => CreateCore(
 0320                options,
 0321                collectionInfo,
 0322                new ConcurrentQueueOfTConverter<TCollection, TElement>());
 323
 324        /// <summary>
 325        /// Creates serialization metadata for types assignable to <see cref="IEnumerable{T}"/>.
 326        /// </summary>
 327        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 328        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 329        /// <param name="options"></param>
 330        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 331        /// <returns>Serialization metadata for the given type.</returns>
 332        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 333        public static JsonTypeInfo<TCollection> CreateIEnumerableInfo<TCollection, TElement>(
 334            JsonSerializerOptions options,
 335            JsonCollectionInfoValues<TCollection> collectionInfo)
 336            where TCollection : IEnumerable<TElement>
 0337            => CreateCore(
 0338                options,
 0339                collectionInfo,
 0340                new IEnumerableOfTConverter<TCollection, TElement>());
 341
 342        /// <summary>
 343        /// Creates serialization metadata for types assignable to <see cref="IAsyncEnumerable{T}"/>.
 344        /// </summary>
 345        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 346        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 347        /// <param name="options"></param>
 348        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 349        /// <returns>Serialization metadata for the given type.</returns>
 350        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 351        public static JsonTypeInfo<TCollection> CreateIAsyncEnumerableInfo<TCollection, TElement>(
 352            JsonSerializerOptions options,
 353            JsonCollectionInfoValues<TCollection> collectionInfo)
 354            where TCollection : IAsyncEnumerable<TElement>
 0355            => CreateCore(
 0356                options,
 0357                collectionInfo,
 0358                new IAsyncEnumerableOfTConverter<TCollection, TElement>());
 359
 360        /// <summary>
 361        /// Creates serialization metadata for types assignable to <see cref="IDictionary"/>.
 362        /// </summary>
 363        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 364        /// <param name="options"></param>
 365        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 366        /// <returns>Serialization metadata for the given type.</returns>
 367        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 368        public static JsonTypeInfo<TCollection> CreateIDictionaryInfo<TCollection>(
 369            JsonSerializerOptions options,
 370            JsonCollectionInfoValues<TCollection> collectionInfo)
 371            where TCollection : IDictionary
 0372            => CreateCore(
 0373                options,
 0374                collectionInfo,
 0375                new IDictionaryConverter<TCollection>());
 376
 377#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved
 378        /// <summary>
 379        /// Creates serialization metadata for <see cref="System.Collections.Stack"/> types.
 380        /// </summary>
 381        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 382        /// <param name="options"></param>
 383        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 384        /// <param name="addFunc">A method for adding elements to the collection when using the serializer's code-paths.
 385        /// <returns>Serialization metadata for the given type.</returns>
 386        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 387#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved
 388        public static JsonTypeInfo<TCollection> CreateStackInfo<TCollection>(
 389            JsonSerializerOptions options,
 390            JsonCollectionInfoValues<TCollection> collectionInfo,
 391            Action<TCollection, object?> addFunc)
 392            where TCollection : IEnumerable
 0393            => CreateStackOrQueueInfo(options, collectionInfo, addFunc);
 394
 395#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved
 396        /// <summary>
 397        /// Creates serialization metadata for <see cref="System.Collections.Queue"/> types.
 398        /// </summary>
 399        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 400        /// <param name="options"></param>
 401        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 402        /// <param name="addFunc">A method for adding elements to the collection when using the serializer's code-paths.
 403        /// <returns>Serialization metadata for the given type.</returns>
 404        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 405#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved
 406        public static JsonTypeInfo<TCollection> CreateQueueInfo<TCollection>(
 407            JsonSerializerOptions options,
 408            JsonCollectionInfoValues<TCollection> collectionInfo,
 409            Action<TCollection, object?> addFunc)
 410            where TCollection : IEnumerable
 0411            => CreateStackOrQueueInfo(options, collectionInfo, addFunc);
 412
 413        private static JsonTypeInfo<TCollection> CreateStackOrQueueInfo<TCollection>(
 414            JsonSerializerOptions options,
 415            JsonCollectionInfoValues<TCollection> collectionInfo,
 416            Action<TCollection, object?> addFunc)
 417            where TCollection : IEnumerable
 0418        {
 0419            ArgumentNullException.ThrowIfNull(addFunc);
 420
 0421            return CreateCore(
 0422                options,
 0423                collectionInfo,
 0424                new StackOrQueueConverter<TCollection>(),
 0425                createObjectWithArgs: null,
 0426                addFunc: addFunc);
 0427        }
 428
 429        /// <summary>
 430        /// Creates serialization metadata for types assignable to <see cref="IList"/>.
 431        /// </summary>
 432        /// <typeparam name="TCollection">The generic definition of the type.</typeparam>
 433        /// <param name="options"></param>
 434        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 435        /// <returns>Serialization metadata for the given type.</returns>
 436        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 437        public static JsonTypeInfo<TCollection> CreateIEnumerableInfo<TCollection>(
 438            JsonSerializerOptions options,
 439            JsonCollectionInfoValues<TCollection> collectionInfo)
 440            where TCollection : IEnumerable
 0441            => CreateCore(
 0442                options,
 0443                collectionInfo,
 0444                new IEnumerableConverter<TCollection>());
 445
 446        /// <summary>
 447        /// Creates serialization metadata for <see cref="Memory{T}"/>.
 448        /// </summary>
 449        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 450        /// <param name="options">The <see cref="JsonSerializerOptions"/> to use.</param>
 451        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 452        /// <returns>Serialization metadata for the given type.</returns>
 453        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 454        public static JsonTypeInfo<Memory<TElement>> CreateMemoryInfo<TElement>(JsonSerializerOptions options, JsonColle
 0455            => CreateCore(
 0456                options,
 0457                collectionInfo,
 0458                new MemoryConverter<TElement>());
 459
 460        /// <summary>
 461        /// Creates serialization metadata for <see cref="ReadOnlyMemory{T}"/>.
 462        /// </summary>
 463        /// <typeparam name="TElement">The generic definition of the element type.</typeparam>
 464        /// <param name="options">The <see cref="JsonSerializerOptions"/> to use.</param>
 465        /// <param name="collectionInfo">Provides serialization metadata about the collection type.</param>
 466        /// <returns>Serialization metadata for the given type.</returns>
 467        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 468        public static JsonTypeInfo<ReadOnlyMemory<TElement>> CreateReadOnlyMemoryInfo<TElement>(JsonSerializerOptions op
 0469            => CreateCore(
 0470                options,
 0471                collectionInfo,
 0472                new ReadOnlyMemoryConverter<TElement>());
 473    }
 474}

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Metadata\JsonMetadataServices.Converters.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Text.Json.Nodes;
 5using System.Text.Json.Serialization.Converters;
 6
 7namespace System.Text.Json.Serialization.Metadata
 8{
 9    public static partial class JsonMetadataServices
 10    {
 11        /// <summary>
 12        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="bool"/> values.
 13        /// </summary>
 14        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 115        public static JsonConverter<bool> BooleanConverter => s_booleanConverter ??= new BooleanConverter();
 16        private static JsonConverter<bool>? s_booleanConverter;
 17
 18        /// <summary>
 19        /// Returns a <see cref="JsonConverter{T}"/> instance that converts byte array values.
 20        /// </summary>
 21        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 122        public static JsonConverter<byte[]?> ByteArrayConverter => s_byteArrayConverter ??= new ByteArrayConverter();
 23        private static JsonConverter<byte[]?>? s_byteArrayConverter;
 24
 25        /// <summary>
 26        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="byte"/> values.
 27        /// </summary>
 28        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 129        public static JsonConverter<byte> ByteConverter => s_byteConverter ??= new ByteConverter();
 30        private static JsonConverter<byte>? s_byteConverter;
 31
 32        /// <summary>
 33        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="char"/> values.
 34        /// </summary>
 35        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 136        public static JsonConverter<char> CharConverter => s_charConverter ??= new CharConverter();
 37        private static JsonConverter<char>? s_charConverter;
 38
 39        /// <summary>
 40        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="DateTime"/> values.
 41        /// </summary>
 42        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 143        public static JsonConverter<DateTime> DateTimeConverter => s_dateTimeConverter ??= new DateTimeConverter();
 44        private static JsonConverter<DateTime>? s_dateTimeConverter;
 45
 46        /// <summary>
 47        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="DateTimeOffset"/> values.
 48        /// </summary>
 49        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 150        public static JsonConverter<DateTimeOffset> DateTimeOffsetConverter => s_dateTimeOffsetConverter ??= new DateTim
 51        private static JsonConverter<DateTimeOffset>? s_dateTimeOffsetConverter;
 52
 53#if NET
 54        /// <summary>
 55        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="DateOnly"/> values.
 56        /// </summary>
 57        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 158        public static JsonConverter<DateOnly> DateOnlyConverter => s_dateOnlyConverter ??= new DateOnlyConverter();
 59        private static JsonConverter<DateOnly>? s_dateOnlyConverter;
 60
 61        /// <summary>
 62        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="TimeOnly"/> values.
 63        /// </summary>
 64        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 165        public static JsonConverter<TimeOnly> TimeOnlyConverter => s_timeOnlyConverter ??= new TimeOnlyConverter();
 66        private static JsonConverter<TimeOnly>? s_timeOnlyConverter;
 67#endif
 68
 69        /// <summary>
 70        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="decimal"/> values.
 71        /// </summary>
 72        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 173        public static JsonConverter<decimal> DecimalConverter => s_decimalConverter ??= new DecimalConverter();
 74        private static JsonConverter<decimal>? s_decimalConverter;
 75
 76        /// <summary>
 77        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="double"/> values.
 78        /// </summary>
 79        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 180        public static JsonConverter<double> DoubleConverter => s_doubleConverter ??= new DoubleConverter();
 81        private static JsonConverter<double>? s_doubleConverter;
 82
 83        /// <summary>
 84        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="Guid"/> values.
 85        /// </summary>
 86        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 187        public static JsonConverter<Guid> GuidConverter => s_guidConverter ??= new GuidConverter();
 88        private static JsonConverter<Guid>? s_guidConverter;
 89
 90        /// <summary>
 91        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="short"/> values.
 92        /// </summary>
 93        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 194        public static JsonConverter<short> Int16Converter => s_int16Converter ??= new Int16Converter();
 95        private static JsonConverter<short>? s_int16Converter;
 96
 97        /// <summary>
 98        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="int"/> values.
 99        /// </summary>
 100        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1101        public static JsonConverter<int> Int32Converter => s_int32Converter ??= new Int32Converter();
 102        private static JsonConverter<int>? s_int32Converter;
 103
 104        /// <summary>
 105        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="long"/> values.
 106        /// </summary>
 107        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1108        public static JsonConverter<long> Int64Converter => s_int64Converter ??= new Int64Converter();
 109        private static JsonConverter<long>? s_int64Converter;
 110
 111#if NET
 112        /// <summary>
 113        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="Int128"/> values.
 114        /// </summary>
 115        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1116        public static JsonConverter<Int128> Int128Converter => s_int128Converter ??= new Int128Converter();
 117        private static JsonConverter<Int128>? s_int128Converter;
 118
 119        /// <summary>
 120        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="UInt128"/> values.
 121        /// </summary>
 122        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 123        [CLSCompliant(false)]
 1124        public static JsonConverter<UInt128> UInt128Converter => s_uint128Converter ??= new UInt128Converter();
 125        private static JsonConverter<UInt128>? s_uint128Converter;
 126#endif
 127
 128        /// <summary>
 129        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="JsonArray"/> values.
 130        /// </summary>
 131        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 0132        public static JsonConverter<JsonArray?> JsonArrayConverter => s_jsonArrayConverter ??= new JsonArrayConverter();
 133        private static JsonConverter<JsonArray?>? s_jsonArrayConverter;
 134
 135        /// <summary>
 136        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="JsonElement"/> values.
 137        /// </summary>
 138        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1139        public static JsonConverter<JsonElement> JsonElementConverter => s_jsonElementConverter ??= new JsonElementConve
 140        private static JsonConverter<JsonElement>? s_jsonElementConverter;
 141
 142        /// <summary>
 143        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="JsonNode"/> values.
 144        /// </summary>
 145        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 0146        public static JsonConverter<JsonNode?> JsonNodeConverter => s_jsonNodeConverter ??= new JsonNodeConverter();
 147        private static JsonConverter<JsonNode?>? s_jsonNodeConverter;
 148
 149        /// <summary>
 150        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="JsonObject"/> values.
 151        /// </summary>
 152        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 0153        public static JsonConverter<JsonObject?> JsonObjectConverter => s_jsonObjectConverter ??= new JsonObjectConverte
 154        private static JsonConverter<JsonObject?>? s_jsonObjectConverter;
 155
 156        /// <summary>
 157        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="JsonArray"/> values.
 158        /// </summary>
 159        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 0160        public static JsonConverter<JsonValue?> JsonValueConverter => s_jsonValueConverter ??= new JsonValueConverter();
 161        private static JsonConverter<JsonValue?>? s_jsonValueConverter;
 162
 163        /// <summary>
 164        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="JsonDocument"/> values.
 165        /// </summary>
 166        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1167        public static JsonConverter<JsonDocument?> JsonDocumentConverter => s_jsonDocumentConverter ??= new JsonDocument
 168        private static JsonConverter<JsonDocument?>? s_jsonDocumentConverter;
 169
 170        /// <summary>
 171        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="Memory{Byte}"/> values.
 172        /// </summary>
 173        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1174        public static JsonConverter<Memory<byte>> MemoryByteConverter => s_memoryByteConverter ??= new MemoryByteConvert
 175        private static JsonConverter<Memory<byte>>? s_memoryByteConverter;
 176
 177        /// <summary>
 178        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="ReadOnlyMemory{Byte}"/> values.
 179        /// </summary>
 180        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1181        public static JsonConverter<ReadOnlyMemory<byte>> ReadOnlyMemoryByteConverter => s_readOnlyMemoryByteConverter ?
 182        private static JsonConverter<ReadOnlyMemory<byte>>? s_readOnlyMemoryByteConverter;
 183
 184        /// <summary>
 185        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="object"/> values.
 186        /// </summary>
 187        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1188        public static JsonConverter<object?> ObjectConverter => s_objectConverter ??= new DefaultObjectConverter();
 189        private static JsonConverter<object?>? s_objectConverter;
 190
 191#if NET
 192        /// <summary>
 193        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="Half"/> values.
 194        /// </summary>
 195        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1196        public static JsonConverter<Half> HalfConverter => s_halfConverter ??= new HalfConverter();
 197        private static JsonConverter<Half>? s_halfConverter;
 198#endif
 199
 200        /// <summary>
 201        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="float"/> values.
 202        /// </summary>
 203        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1204        public static JsonConverter<float> SingleConverter => s_singleConverter ??= new SingleConverter();
 205        private static JsonConverter<float>? s_singleConverter;
 206
 207        /// <summary>
 208        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="sbyte"/> values.
 209        /// </summary>
 210        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 211        [CLSCompliant(false)]
 1212        public static JsonConverter<sbyte> SByteConverter => s_sbyteConverter ??= new SByteConverter();
 213        private static JsonConverter<sbyte>? s_sbyteConverter;
 214
 215        /// <summary>
 216        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="string"/> values.
 217        /// </summary>
 218        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1219        public static JsonConverter<string?> StringConverter => s_stringConverter ??= new StringConverter();
 220        private static JsonConverter<string?>? s_stringConverter;
 221
 222        /// <summary>
 223        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="TimeSpan"/> values.
 224        /// </summary>
 225        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1226        public static JsonConverter<TimeSpan> TimeSpanConverter => s_timeSpanConverter ??= new TimeSpanConverter();
 227        private static JsonConverter<TimeSpan>? s_timeSpanConverter;
 228
 229        /// <summary>
 230        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="ushort"/> values.
 231        /// </summary>
 232        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 233        [CLSCompliant(false)]
 1234        public static JsonConverter<ushort> UInt16Converter => s_uint16Converter ??= new UInt16Converter();
 235        private static JsonConverter<ushort>? s_uint16Converter;
 236
 237        /// <summary>
 238        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="uint"/> values.
 239        /// </summary>
 240        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 241        [CLSCompliant(false)]
 1242        public static JsonConverter<uint> UInt32Converter => s_uint32Converter ??= new UInt32Converter();
 243        private static JsonConverter<uint>? s_uint32Converter;
 244
 245        /// <summary>
 246        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="ulong"/> values.
 247        /// </summary>
 248        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 249        [CLSCompliant(false)]
 1250        public static JsonConverter<ulong> UInt64Converter => s_uint64Converter ??= new UInt64Converter();
 251        private static JsonConverter<ulong>? s_uint64Converter;
 252
 253        /// <summary>
 254        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="Uri"/> values.
 255        /// </summary>
 256        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1257        public static JsonConverter<Uri?> UriConverter => s_uriConverter ??= new UriConverter();
 258        private static JsonConverter<Uri?>? s_uriConverter;
 259
 260        /// <summary>
 261        /// Returns a <see cref="JsonConverter{T}"/> instance that converts <see cref="Version"/> values.
 262        /// </summary>
 263        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 1264        public static JsonConverter<Version?> VersionConverter => s_versionConverter ??= new VersionConverter();
 265        private static JsonConverter<Version?>? s_versionConverter;
 266
 267        /// <summary>
 268        /// Creates a <see cref="JsonConverter{T}"/> instance that throws <see cref="NotSupportedException"/>.
 269        /// </summary>
 270        /// <typeparam name="T">The generic definition for the type.</typeparam>
 271        /// <returns>A <see cref="JsonConverter{T}"/> instance that throws <see cref="NotSupportedException"/></returns>
 272        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 273        public static JsonConverter<T> GetUnsupportedTypeConverter<T>()
 0274            => new UnsupportedTypeConverter<T>();
 275
 276        /// <summary>
 277        /// Creates a <see cref="JsonConverter{T}"/> instance that converts <typeparamref name="T"/> values.
 278        /// </summary>
 279        /// <typeparam name="T">The generic definition for the enum type.</typeparam>
 280        /// <param name="options">The <see cref="JsonSerializerOptions"/> to use for serialization and deserialization.<
 281        /// <returns>A <see cref="JsonConverter{T}"/> instance that converts <typeparamref name="T"/> values.</returns>
 282        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 283        public static JsonConverter<T> GetEnumConverter<T>(JsonSerializerOptions options) where T : struct, Enum
 0284        {
 0285            ArgumentNullException.ThrowIfNull(options);
 286
 0287            return EnumConverterFactory.Helpers.Create<T>(EnumConverterOptions.AllowNumbers, options);
 0288        }
 289
 290        /// <summary>
 291        /// Creates a <see cref="JsonConverter{T}"/> instance that converts <typeparamref name="T?"/> values.
 292        /// </summary>
 293        /// <typeparam name="T">The generic definition for the underlying nullable type.</typeparam>
 294        /// <param name="underlyingTypeInfo">Serialization metadata for the underlying nullable type.</param>
 295        /// <returns>A <see cref="JsonConverter{T}"/> instance that converts <typeparamref name="T?"/> values</returns>
 296        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 297        public static JsonConverter<T?> GetNullableConverter<T>(JsonTypeInfo<T> underlyingTypeInfo) where T : struct
 0298        {
 0299            ArgumentNullException.ThrowIfNull(underlyingTypeInfo);
 300
 0301            JsonConverter<T> underlyingConverter = GetTypedConverter<T>(underlyingTypeInfo.Converter);
 302
 0303            return new NullableConverter<T>(underlyingConverter);
 0304        }
 305
 306        /// <summary>
 307        /// Creates a <see cref="JsonConverter{T}"/> instance that converts <typeparamref name="T?"/> values.
 308        /// </summary>
 309        /// <typeparam name="T">The generic definition for the underlying nullable type.</typeparam>
 310        /// <param name="options">The <see cref="JsonSerializerOptions"/> to use for serialization and deserialization.<
 311        /// <returns>A <see cref="JsonConverter{T}"/> instance that converts <typeparamref name="T?"/> values</returns>
 312        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 313        public static JsonConverter<T?> GetNullableConverter<T>(JsonSerializerOptions options) where T : struct
 0314        {
 0315            ArgumentNullException.ThrowIfNull(options);
 316
 0317            JsonConverter<T> underlyingConverter = GetTypedConverter<T>(options.GetConverterInternal(typeof(T)));
 318
 0319            return new NullableConverter<T>(underlyingConverter);
 0320        }
 321
 322        internal static JsonConverter<T> GetTypedConverter<T>(JsonConverter converter)
 0323        {
 0324            JsonConverter<T>? typedConverter = converter as JsonConverter<T>;
 0325            if (typedConverter == null)
 0326            {
 0327                throw new InvalidOperationException(SR.Format(SR.SerializationConverterNotCompatible, typedConverter, ty
 328            }
 329
 0330            return typedConverter;
 0331        }
 332    }
 333}

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Metadata\JsonMetadataServices.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.ComponentModel;
 5
 6namespace System.Text.Json.Serialization.Metadata
 7{
 8    /// <summary>
 9    /// Provides helpers to create and initialize metadata for JSON-serializable types.
 10    /// </summary>
 11    /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called dir
 12    [EditorBrowsable(EditorBrowsableState.Never)]
 13    public static partial class JsonMetadataServices
 14    {
 15        /// <summary>
 16        /// Creates metadata for a property or field.
 17        /// </summary>
 18        /// <typeparam name="T">The type that the converter for the property returns or accepts when converting JSON dat
 19        /// <param name="options">The <see cref="JsonSerializerOptions"/> to initialize the metadata with.</param>
 20        /// <param name="propertyInfo">Provides serialization metadata about the property or field.</param>
 21        /// <returns>A <see cref="JsonPropertyInfo"/> instance initialized with the provided metadata.</returns>
 22        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 23        public static JsonPropertyInfo CreatePropertyInfo<T>(JsonSerializerOptions options, JsonPropertyInfoValues<T> pr
 024        {
 025            ArgumentNullException.ThrowIfNull(options);
 026            ArgumentNullException.ThrowIfNull(propertyInfo);
 27
 028            Type? declaringType = propertyInfo.DeclaringType;
 029            if (declaringType == null)
 030            {
 031                throw new ArgumentException(nameof(propertyInfo.DeclaringType));
 32            }
 33
 034            string? propertyName = propertyInfo.PropertyName;
 035            if (propertyName == null)
 036            {
 037                throw new ArgumentException(nameof(propertyInfo.PropertyName));
 38            }
 39
 040            if (!propertyInfo.IsProperty && propertyInfo.IsVirtual)
 041            {
 042                throw new InvalidOperationException(SR.Format(SR.FieldCannotBeVirtual, nameof(propertyInfo.IsProperty), 
 43            }
 44
 045            return CreatePropertyInfoCore(propertyInfo, options);
 046        }
 47
 48        /// <summary>
 49        /// Creates metadata for a complex class or struct.
 50        /// </summary>
 51        /// <param name="options">The <see cref="JsonSerializerOptions"/> to initialize the metadata with.</param>
 52        /// <param name="objectInfo">Provides serialization metadata about an object type with constructors, properties,
 53        /// <typeparam name="T">The type of the class or struct.</typeparam>
 54        /// <exception cref="ArgumentNullException">Thrown when <paramref name="options"/> or <paramref name="objectInfo
 55        /// <returns>A <see cref="JsonTypeInfo{T}"/> instance representing the class or struct.</returns>
 56        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 57        public static JsonTypeInfo<T> CreateObjectInfo<T>(JsonSerializerOptions options, JsonObjectInfoValues<T> objectI
 058        {
 059            ArgumentNullException.ThrowIfNull(options);
 060            ArgumentNullException.ThrowIfNull(objectInfo);
 61
 062            return CreateCore(options, objectInfo);
 063        }
 64
 65        /// <summary>
 66        /// Creates metadata for a primitive or a type with a custom converter.
 67        /// </summary>
 68        /// <typeparam name="T">The generic type definition.</typeparam>
 69        /// <returns>A <see cref="JsonTypeInfo{T}"/> instance representing the type.</returns>
 70        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called
 71        public static JsonTypeInfo<T> CreateValueInfo<T>(JsonSerializerOptions options, JsonConverter converter)
 072        {
 073            ArgumentNullException.ThrowIfNull(options);
 074            ArgumentNullException.ThrowIfNull(converter);
 75
 076            JsonTypeInfo<T> info = CreateCore<T>(converter, options);
 077            return info;
 078        }
 79    }
 80}

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Metadata\JsonMetadataServices.Helpers.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.Reflection;
 6using System.Text.Json.Serialization.Converters;
 7
 8namespace System.Text.Json.Serialization.Metadata
 9{
 10    public static partial class JsonMetadataServices
 11    {
 12        /// <summary>
 13        /// Creates serialization metadata for a type using a simple converter.
 14        /// </summary>
 15        private static JsonTypeInfo<T> CreateCore<T>(JsonConverter converter, JsonSerializerOptions options)
 016        {
 017            var typeInfo = new JsonTypeInfo<T>(converter, options);
 018            typeInfo.PopulatePolymorphismMetadata();
 019            typeInfo.MapInterfaceTypesToCallbacks();
 20
 21            // Plug in any converter configuration -- should be run last.
 022            converter.ConfigureJsonTypeInfo(typeInfo, options);
 023            typeInfo.IsCustomized = false;
 024            return typeInfo;
 025        }
 26
 27        /// <summary>
 28        /// Creates serialization metadata for an object.
 29        /// </summary>
 30        private static JsonTypeInfo<T> CreateCore<T>(JsonSerializerOptions options, JsonObjectInfoValues<T> objectInfo)
 031        {
 032            JsonConverter<T> converter = GetConverter(objectInfo);
 033            var typeInfo = new JsonTypeInfo<T>(converter, options);
 034            if (objectInfo.ObjectWithParameterizedConstructorCreator != null)
 035            {
 36                // NB parameter metadata must be populated *before* property metadata
 37                // so that properties can be linked to their associated parameters.
 038                typeInfo.CreateObjectWithArgs = objectInfo.ObjectWithParameterizedConstructorCreator;
 039                PopulateParameterInfoValues(typeInfo, objectInfo.ConstructorParameterMetadataInitializer);
 040            }
 41            else
 042            {
 043                typeInfo.SetCreateObjectIfCompatible(objectInfo.ObjectCreator);
 044                typeInfo.CreateObjectForExtensionDataProperty = ((JsonTypeInfo)typeInfo).CreateObject;
 045            }
 46
 047            if (objectInfo.PropertyMetadataInitializer != null)
 048            {
 049                typeInfo.SourceGenDelayedPropertyInitializer = objectInfo.PropertyMetadataInitializer;
 050            }
 51            else
 052            {
 053                typeInfo.PropertyMetadataSerializationNotSupported = true;
 054            }
 55
 056            typeInfo.ConstructorAttributeProviderFactory = objectInfo.ConstructorAttributeProviderFactory;
 057            typeInfo.SerializeHandler = objectInfo.SerializeHandler;
 058            typeInfo.NumberHandling = objectInfo.NumberHandling;
 059            typeInfo.PopulatePolymorphismMetadata();
 060            typeInfo.MapInterfaceTypesToCallbacks();
 61
 62            // Plug in any converter configuration -- should be run last.
 063            converter.ConfigureJsonTypeInfo(typeInfo, options);
 064            typeInfo.IsCustomized = false;
 065            return typeInfo;
 066        }
 67
 68        /// <summary>
 69        /// Creates serialization metadata for a collection.
 70        /// </summary>
 71        private static JsonTypeInfo<T> CreateCore<T>(
 72            JsonSerializerOptions options,
 73            JsonCollectionInfoValues<T> collectionInfo,
 74            JsonConverter<T> converter,
 75            object? createObjectWithArgs = null,
 76            object? addFunc = null)
 077        {
 078            ArgumentNullException.ThrowIfNull(collectionInfo);
 79
 080            converter = collectionInfo.SerializeHandler != null
 081                ? new JsonMetadataServicesConverter<T>(converter)
 082                : converter;
 83
 084            JsonTypeInfo<T> typeInfo = new JsonTypeInfo<T>(converter, options);
 85
 086            typeInfo.KeyTypeInfo = collectionInfo.KeyInfo;
 087            typeInfo.ElementTypeInfo = collectionInfo.ElementInfo;
 088            Debug.Assert(typeInfo.Kind != JsonTypeInfoKind.None);
 089            typeInfo.NumberHandling = collectionInfo.NumberHandling;
 090            typeInfo.SerializeHandler = collectionInfo.SerializeHandler;
 091            typeInfo.CreateObjectWithArgs = createObjectWithArgs;
 092            typeInfo.AddMethodDelegate = addFunc;
 093            typeInfo.SetCreateObjectIfCompatible(collectionInfo.ObjectCreator);
 094            typeInfo.PopulatePolymorphismMetadata();
 095            typeInfo.MapInterfaceTypesToCallbacks();
 96
 97            // Plug in any converter configuration -- should be run last.
 098            converter.ConfigureJsonTypeInfo(typeInfo, options);
 099            typeInfo.IsCustomized = false;
 0100            return typeInfo;
 0101        }
 102
 103        private static JsonConverter<T> GetConverter<T>(JsonObjectInfoValues<T> objectInfo)
 0104        {
 105#pragma warning disable CS8714 // Nullability of type argument 'T' doesn't match 'notnull' constraint.
 0106            JsonConverter<T> converter = objectInfo.ObjectWithParameterizedConstructorCreator != null
 0107                ? new LargeObjectWithParameterizedConstructorConverter<T>()
 0108                : new ObjectDefaultConverter<T>();
 109#pragma warning restore CS8714
 110
 0111            return objectInfo.SerializeHandler != null
 0112                ? new JsonMetadataServicesConverter<T>(converter)
 0113                : converter;
 0114        }
 115
 116        private static void PopulateParameterInfoValues(JsonTypeInfo typeInfo, Func<JsonParameterInfoValues[]?>? paramFa
 0117        {
 0118            Debug.Assert(typeInfo.Kind is JsonTypeInfoKind.Object);
 0119            Debug.Assert(!typeInfo.IsReadOnly);
 120
 0121            if (paramFactory?.Invoke() is JsonParameterInfoValues[] parameterInfoValues)
 0122            {
 0123                typeInfo.PopulateParameterInfoValues(parameterInfoValues);
 0124            }
 125            else
 0126            {
 0127                typeInfo.PropertyMetadataSerializationNotSupported = true;
 0128            }
 0129        }
 130
 131        internal static void PopulateProperties(JsonTypeInfo typeInfo, JsonTypeInfo.JsonPropertyInfoList propertyList, F
 0132        {
 0133            Debug.Assert(typeInfo.Kind is JsonTypeInfoKind.Object);
 0134            Debug.Assert(!typeInfo.IsConfigured);
 0135            Debug.Assert(typeInfo.Type != JsonTypeInfo.ObjectType);
 0136            Debug.Assert(typeInfo.Converter.ElementType is null);
 137
 0138            JsonSerializerContext? context = typeInfo.Options.TypeInfoResolver as JsonSerializerContext;
 0139            JsonPropertyInfo[] properties = propInitFunc(context!);
 140
 141            // Regardless of the source generator we need to re-run the naming conflict resolution algorithm
 142            // at run time since it is possible that the naming policy or other configs can be different then.
 0143            JsonTypeInfo.PropertyHierarchyResolutionState state = new(typeInfo.Options);
 144
 0145            foreach (JsonPropertyInfo jsonPropertyInfo in properties)
 0146            {
 0147                if (!jsonPropertyInfo.SrcGen_IsPublic)
 0148                {
 0149                    if (jsonPropertyInfo.SrcGen_HasJsonInclude)
 0150                    {
 0151                        Debug.Assert(jsonPropertyInfo.MemberName != null, "MemberName is not set by source gen");
 0152                        ThrowHelper.ThrowInvalidOperationException_JsonIncludeOnInaccessibleProperty(jsonPropertyInfo.Me
 153                    }
 154
 0155                    continue;
 156                }
 157
 0158                if (jsonPropertyInfo.MemberType == MemberTypes.Field && !jsonPropertyInfo.SrcGen_HasJsonInclude && !type
 0159                {
 0160                    continue;
 161                }
 162
 0163                propertyList.AddPropertyWithConflictResolution(jsonPropertyInfo, ref state);
 0164            }
 165
 0166            if (state.IsPropertyOrderSpecified)
 0167            {
 0168                propertyList.SortProperties();
 0169            }
 0170        }
 171
 172        private static JsonPropertyInfo<T> CreatePropertyInfoCore<T>(JsonPropertyInfoValues<T> propertyInfoValues, JsonS
 0173        {
 0174            var propertyInfo = new JsonPropertyInfo<T>(propertyInfoValues.DeclaringType, declaringTypeInfo: null, option
 175
 0176            DeterminePropertyName(propertyInfo,
 0177                declaredPropertyName: propertyInfoValues.PropertyName,
 0178                declaredJsonPropertyName: propertyInfoValues.JsonPropertyName);
 179
 0180            propertyInfo.MemberName = propertyInfoValues.PropertyName;
 0181            propertyInfo.MemberType = propertyInfoValues.IsProperty ? MemberTypes.Property : MemberTypes.Field;
 0182            propertyInfo.SrcGen_IsPublic = propertyInfoValues.IsPublic;
 0183            propertyInfo.SrcGen_HasJsonInclude = propertyInfoValues.HasJsonInclude;
 0184            propertyInfo.IsExtensionData = propertyInfoValues.IsExtensionData;
 0185            propertyInfo.CustomConverter = propertyInfoValues.Converter;
 186
 0187            if (propertyInfo.IgnoreCondition != JsonIgnoreCondition.Always)
 0188            {
 0189                propertyInfo.Get = propertyInfoValues.Getter!;
 0190                propertyInfo.Set = propertyInfoValues.Setter;
 0191            }
 192
 0193            propertyInfo.IgnoreCondition = propertyInfoValues.IgnoreCondition;
 0194            propertyInfo.JsonTypeInfo = propertyInfoValues.PropertyTypeInfo;
 0195            propertyInfo.NumberHandling = propertyInfoValues.NumberHandling;
 0196            propertyInfo.AttributeProviderFactory = propertyInfoValues.AttributeProviderFactory;
 197
 0198            return propertyInfo;
 0199        }
 200
 201        private static void DeterminePropertyName(
 202            JsonPropertyInfo propertyInfo,
 203            string declaredPropertyName,
 204            string? declaredJsonPropertyName)
 0205        {
 206            string? name;
 207
 208            // Property name settings.
 0209            if (declaredJsonPropertyName != null)
 0210            {
 0211                name = declaredJsonPropertyName;
 0212            }
 0213            else if (propertyInfo.Options.PropertyNamingPolicy == null)
 0214            {
 0215                name = declaredPropertyName;
 0216            }
 217            else
 0218            {
 0219                name = propertyInfo.Options.PropertyNamingPolicy.ConvertName(declaredPropertyName);
 0220            }
 221
 222            // Compat: We need to do validation before we assign Name so that we get InvalidOperationException rather th
 0223            if (name == null)
 0224            {
 0225                ThrowHelper.ThrowInvalidOperationException_SerializerPropertyNameNull(propertyInfo);
 226            }
 227
 0228            propertyInfo.Name = name;
 0229        }
 230    }
 231}

Methods/Properties

CreateArrayInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TElement[]>)
CreateListInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateDictionaryInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateImmutableDictionaryInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>,System.Func`2<System.Collections.Generic.IEnumerable`1<System.Collections.Generic.KeyValuePair`2<TKey,TValue>>,TCollection>)
CreateIDictionaryInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateIReadOnlyDictionaryInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateImmutableEnumerableInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>,System.Func`2<System.Collections.Generic.IEnumerable`1<TElement>,TCollection>)
CreateIListInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateISetInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateIReadOnlySetInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateICollectionInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateStackInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateQueueInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateConcurrentStackInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateConcurrentQueueInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateIEnumerableInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateIAsyncEnumerableInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>)
CreateStackInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>,System.Action`2<TCollection,System.Object>)
CreateQueueInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>,System.Action`2<TCollection,System.Object>)
CreateStackOrQueueInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<TCollection>,System.Action`2<TCollection,System.Object>)
CreateMemoryInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<System.Memory`1<TElement>>)
CreateReadOnlyMemoryInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<System.ReadOnlyMemory`1<TElement>>)
BooleanConverter()
ByteArrayConverter()
ByteConverter()
CharConverter()
DateTimeConverter()
DateTimeOffsetConverter()
DateOnlyConverter()
TimeOnlyConverter()
DecimalConverter()
DoubleConverter()
GuidConverter()
Int16Converter()
Int32Converter()
Int64Converter()
Int128Converter()
UInt128Converter()
JsonArrayConverter()
JsonElementConverter()
JsonNodeConverter()
JsonObjectConverter()
JsonValueConverter()
JsonDocumentConverter()
MemoryByteConverter()
ReadOnlyMemoryByteConverter()
ObjectConverter()
HalfConverter()
SingleConverter()
SByteConverter()
StringConverter()
TimeSpanConverter()
UInt16Converter()
UInt32Converter()
UInt64Converter()
UriConverter()
VersionConverter()
GetUnsupportedTypeConverter()
GetEnumConverter(System.Text.Json.JsonSerializerOptions)
GetNullableConverter(System.Text.Json.Serialization.Metadata.JsonTypeInfo`1<T>)
GetNullableConverter(System.Text.Json.JsonSerializerOptions)
GetTypedConverter(System.Text.Json.Serialization.JsonConverter)
CreatePropertyInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues`1<T>)
CreateObjectInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonObjectInfoValues`1<T>)
CreateValueInfo(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.JsonConverter)
CreateCore(System.Text.Json.Serialization.JsonConverter,System.Text.Json.JsonSerializerOptions)
CreateCore(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonObjectInfoValues`1<T>)
CreateCore(System.Text.Json.JsonSerializerOptions,System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues`1<T>,System.Text.Json.Serialization.JsonConverter`1<T>,System.Object,System.Object)
GetConverter(System.Text.Json.Serialization.Metadata.JsonObjectInfoValues`1<T>)
PopulateParameterInfoValues(System.Text.Json.Serialization.Metadata.JsonTypeInfo,System.Func`1<System.Text.Json.Serialization.Metadata.JsonParameterInfoValues[]>)
PopulateProperties(System.Text.Json.Serialization.Metadata.JsonTypeInfo,System.Text.Json.Serialization.Metadata.JsonTypeInfo/JsonPropertyInfoList,System.Func`2<System.Text.Json.Serialization.JsonSerializerContext,System.Text.Json.Serialization.Metadata.JsonPropertyInfo[]>)
CreatePropertyInfoCore(System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues`1<T>,System.Text.Json.JsonSerializerOptions)
DeterminePropertyName(System.Text.Json.Serialization.Metadata.JsonPropertyInfo,System.String,System.String)