Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Updated serialization and deserialization of enum collection to remov…
Browse files Browse the repository at this point in the history
…e LINQ to reduce NativeAOT output size
  • Loading branch information
filipnavara committed May 21, 2024
1 parent 087222f commit 243405a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/FormParseNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ private void AssignFieldValues<T>(T item) where T : IParsable
IEnumerable<T?> IParseNode.GetCollectionOfEnumValues<T>()
#endif
{
return DecodedValue.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries).Select(v => GetEnumValueInternal<T>(v));
foreach (var v in DecodedValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
yield return GetEnumValueInternal<T>(v);
}
#if NET5_0_OR_GREATER
T? IParseNode.GetEnumValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>()
Expand Down
20 changes: 17 additions & 3 deletions src/FormSerializationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,23 @@ public void WriteTimeValue(string? key, Time? value) {
public void WriteCollectionOfEnumValues<T>(string? key, IEnumerable<T?>? 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());
}
/// <inheritdoc/>
#if NET5_0_OR_GREATER
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Kiota.Serialization.Form.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageProjectUrl>https://aka.ms/kiota/docs</PackageProjectUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<VersionPrefix>1.2.1</VersionPrefix>
<VersionPrefix>1.2.2</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down

0 comments on commit 243405a

Please sign in to comment.