|
8 | 8 | using System.ComponentModel; |
9 | 9 | using System.Diagnostics; |
10 | 10 | using System.IO; |
| 11 | +using System.Linq; |
11 | 12 | using System.Reflection; |
12 | 13 | using System.Runtime.Serialization; |
13 | 14 | using Microsoft.Kiota.Abstractions.Extensions; |
@@ -513,5 +514,29 @@ public void SetContentFromEnum<T>(IRequestAdapter requestAdapter, string content |
513 | 514 | Headers.TryAdd(ContentTypeHeader, contentType); |
514 | 515 | Content = writer.GetSerializedContent(); |
515 | 516 | } |
| 517 | + |
| 518 | + /// <summary> |
| 519 | + /// Sets the request body from a collection of enum values with the specified content type. |
| 520 | + /// </summary> |
| 521 | + /// <param name="requestAdapter">The core service to get the serialization writer from.</param> |
| 522 | + /// <param name="items">The enum values to serialize.</param> |
| 523 | + /// <param name="contentType">The content type to set.</param> |
| 524 | + /// <typeparam name="T">The enum type to serialize.</typeparam> |
| 525 | +#if NET5_0_OR_GREATER |
| 526 | + public void SetContentFromEnumCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(IRequestAdapter requestAdapter, string contentType, IEnumerable<T?> items) where T : struct, Enum |
| 527 | +#else |
| 528 | + public void SetContentFromEnumCollection<T>(IRequestAdapter requestAdapter, string contentType, IEnumerable<T?> items) where T : struct, Enum |
| 529 | +#endif |
| 530 | + { |
| 531 | + using var activity = _activitySource?.StartActivity(nameof(SetContentFromEnumCollection)); |
| 532 | + using var writer = GetSerializationWriter(requestAdapter, contentType, items); |
| 533 | + |
| 534 | + var firstNonNullItem = items.FirstOrDefault(static x => x is not null); |
| 535 | + |
| 536 | + SetRequestType(firstNonNullItem, activity); |
| 537 | + writer.WriteCollectionOfEnumValues(null, items); |
| 538 | + Headers.TryAdd(ContentTypeHeader, contentType); |
| 539 | + Content = writer.GetSerializedContent(); |
| 540 | + } |
516 | 541 | } |
517 | 542 | } |
0 commit comments