diff --git a/CHANGELOG.md b/CHANGELOG.md index d733799..7aa3b58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.2.2] - 2024-05-21 + +### Changed + +- Updated serialization and deserialization of enum collection to remove LINQ to reduce NativeAOT output size + ## [1.2.1] - 2024-05-20 ### Changed diff --git a/src/FormParseNode.cs b/src/FormParseNode.cs index 1300d36..e9d0457 100644 --- a/src/FormParseNode.cs +++ b/src/FormParseNode.cs @@ -192,7 +192,8 @@ private void AssignFieldValues(T item) where T : IParsable IEnumerable IParseNode.GetCollectionOfEnumValues() #endif { - return DecodedValue.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries).Select(v => GetEnumValueInternal(v)); + foreach (var v in DecodedValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) + yield return GetEnumValueInternal(v); } #if NET5_0_OR_GREATER T? IParseNode.GetEnumValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>() diff --git a/src/FormSerializationWriter.cs b/src/FormSerializationWriter.cs index 08528d6..a4fe0b4 100644 --- a/src/FormSerializationWriter.cs +++ b/src/FormSerializationWriter.cs @@ -206,9 +206,23 @@ public void WriteTimeValue(string? key, Time? value) { public void WriteCollectionOfEnumValues(string? key, IEnumerable? values) where T : struct, Enum #endif { - if(values == null || !values.Any()) return; - WriteStringValue(key, string.Join(",", values.Where(static x => x.HasValue) - .Select(static x => x!.Value.ToString().ToFirstCharacterLowerCase()))); + if(values == null) return; + + StringBuilder? valueNames = null; + foreach(var x in values) + { + if(x.HasValue && Enum.GetName(typeof(T), x.Value) is string valueName) + { + if(valueNames == null) + valueNames = new StringBuilder(); + else + valueNames.Append(","); + valueNames.Append(valueName.ToFirstCharacterLowerCase()); + } + } + + if(valueNames is not null) + WriteStringValue(key, valueNames.ToString()); } /// #if NET5_0_OR_GREATER diff --git a/src/Microsoft.Kiota.Serialization.Form.csproj b/src/Microsoft.Kiota.Serialization.Form.csproj index e755656..d64612f 100644 --- a/src/Microsoft.Kiota.Serialization.Form.csproj +++ b/src/Microsoft.Kiota.Serialization.Form.csproj @@ -16,7 +16,7 @@ https://aka.ms/kiota/docs true true - 1.2.1 + 1.2.2 true true