| | | 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 | | |
| | | 4 | | using System.Collections; |
| | | 5 | | using System.Collections.Concurrent; |
| | | 6 | | using System.Collections.Generic; |
| | | 7 | | using System.Text.Json.Serialization.Converters; |
| | | 8 | | |
| | | 9 | | namespace 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 |
| | 0 | 22 | | => CreateCore( |
| | 0 | 23 | | options, |
| | 0 | 24 | | collectionInfo, |
| | 0 | 25 | | 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> |
| | 0 | 40 | | => CreateCore( |
| | 0 | 41 | | options, |
| | 0 | 42 | | collectionInfo, |
| | 0 | 43 | | 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 |
| | 0 | 60 | | => CreateCore( |
| | 0 | 61 | | options, |
| | 0 | 62 | | collectionInfo, |
| | 0 | 63 | | 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 |
| | 0 | 86 | | { |
| | 0 | 87 | | ArgumentNullException.ThrowIfNull(createRangeFunc); |
| | | 88 | | |
| | 0 | 89 | | return CreateCore( |
| | 0 | 90 | | options, |
| | 0 | 91 | | collectionInfo, |
| | 0 | 92 | | new ImmutableDictionaryOfTKeyTValueConverter<TCollection, TKey, TValue>(), |
| | 0 | 93 | | createObjectWithArgs: createRangeFunc); |
| | 0 | 94 | | } |
| | | 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 |
| | 0 | 111 | | => CreateCore( |
| | 0 | 112 | | options, |
| | 0 | 113 | | collectionInfo, |
| | 0 | 114 | | 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 |
| | 0 | 131 | | => CreateCore( |
| | 0 | 132 | | options, |
| | 0 | 133 | | collectionInfo, |
| | 0 | 134 | | 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> |
| | 0 | 151 | | { |
| | 0 | 152 | | ArgumentNullException.ThrowIfNull(createRangeFunc); |
| | | 153 | | |
| | 0 | 154 | | return CreateCore( |
| | 0 | 155 | | options, |
| | 0 | 156 | | collectionInfo, |
| | 0 | 157 | | new ImmutableEnumerableOfTConverter<TCollection, TElement>(), |
| | 0 | 158 | | createObjectWithArgs: createRangeFunc); |
| | 0 | 159 | | } |
| | | 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 |
| | 0 | 173 | | => CreateCore( |
| | 0 | 174 | | options, |
| | 0 | 175 | | collectionInfo, |
| | 0 | 176 | | 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> |
| | 0 | 191 | | => CreateCore( |
| | 0 | 192 | | options, |
| | 0 | 193 | | collectionInfo, |
| | 0 | 194 | | 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> |
| | 0 | 209 | | => CreateCore( |
| | 0 | 210 | | options, |
| | 0 | 211 | | collectionInfo, |
| | 0 | 212 | | 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> |
| | 0 | 228 | | => CreateCore( |
| | 0 | 229 | | options, |
| | 0 | 230 | | collectionInfo, |
| | 0 | 231 | | 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> |
| | 0 | 247 | | => CreateCore( |
| | 0 | 248 | | options, |
| | 0 | 249 | | collectionInfo, |
| | 0 | 250 | | 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> |
| | 0 | 265 | | => CreateCore( |
| | 0 | 266 | | options, |
| | 0 | 267 | | collectionInfo, |
| | 0 | 268 | | 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> |
| | 0 | 283 | | => CreateCore( |
| | 0 | 284 | | options, |
| | 0 | 285 | | collectionInfo, |
| | 0 | 286 | | 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> |
| | 0 | 301 | | => CreateCore( |
| | 0 | 302 | | options, |
| | 0 | 303 | | collectionInfo, |
| | 0 | 304 | | 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> |
| | 0 | 319 | | => CreateCore( |
| | 0 | 320 | | options, |
| | 0 | 321 | | collectionInfo, |
| | 0 | 322 | | 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> |
| | 0 | 337 | | => CreateCore( |
| | 0 | 338 | | options, |
| | 0 | 339 | | collectionInfo, |
| | 0 | 340 | | 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> |
| | 0 | 355 | | => CreateCore( |
| | 0 | 356 | | options, |
| | 0 | 357 | | collectionInfo, |
| | 0 | 358 | | 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 |
| | 0 | 372 | | => CreateCore( |
| | 0 | 373 | | options, |
| | 0 | 374 | | collectionInfo, |
| | 0 | 375 | | 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 |
| | 0 | 393 | | => 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 |
| | 0 | 411 | | => 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 |
| | 0 | 418 | | { |
| | 0 | 419 | | ArgumentNullException.ThrowIfNull(addFunc); |
| | | 420 | | |
| | 0 | 421 | | return CreateCore( |
| | 0 | 422 | | options, |
| | 0 | 423 | | collectionInfo, |
| | 0 | 424 | | new StackOrQueueConverter<TCollection>(), |
| | 0 | 425 | | createObjectWithArgs: null, |
| | 0 | 426 | | addFunc: addFunc); |
| | 0 | 427 | | } |
| | | 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 |
| | 0 | 441 | | => CreateCore( |
| | 0 | 442 | | options, |
| | 0 | 443 | | collectionInfo, |
| | 0 | 444 | | 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 |
| | 0 | 455 | | => CreateCore( |
| | 0 | 456 | | options, |
| | 0 | 457 | | collectionInfo, |
| | 0 | 458 | | 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 |
| | 0 | 469 | | => CreateCore( |
| | 0 | 470 | | options, |
| | 0 | 471 | | collectionInfo, |
| | 0 | 472 | | new ReadOnlyMemoryConverter<TElement>()); |
| | | 473 | | } |
| | | 474 | | } |