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

Commit

Permalink
Merge pull request #107 from IEvangelist/aot-warning-and-cleanup
Browse files Browse the repository at this point in the history
Fix AOT warning issues, and clean up.
  • Loading branch information
andrueastman authored Jan 31, 2024
2 parents 86b23af + e1d98bf commit 1788aaf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

## [1.1.2] - 2024-01-30

### Changed

- Fixed some AOT warnings due to reflection use on enum types.

## [1.1.1] - 2023-11-15

### Added
Expand Down
9 changes: 4 additions & 5 deletions src/FormParseNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public FormParseNode(string rawValue)
Fields = rawValue.Split(new char[] {'&'}, StringSplitOptions.RemoveEmptyEntries)
.Select(static x => x.Split(new char[] {'='}, StringSplitOptions.RemoveEmptyEntries))
.Where(static x => x.Length == 2)
.Select(static x => (key: sanitizeKey(x[0]), value: x[1].Trim()))
.Select(static x => (key: SanitizeKey(x[0]), value: x[1].Trim()))
.GroupBy(static x => x.key, StringComparer.OrdinalIgnoreCase)
.Select(static x => (key: x.Key, value: string.Join(",", x.Select(static y => y.value))))
.ToDictionary(static x => x.key, static x => x.value, StringComparer.OrdinalIgnoreCase);
}
private static string sanitizeKey(string key) {
private static string SanitizeKey(string key) {
if (string.IsNullOrEmpty(key)) return key;
return Uri.UnescapeDataString(key.Trim());
}
Expand All @@ -48,7 +48,7 @@ private static string sanitizeKey(string key) {
/// <inheritdoc/>
public byte? GetByteValue() => byte.TryParse(DecodedValue, out var result) ? result : null;
/// <inheritdoc/>
public IParseNode? GetChildNode(string identifier) => Fields.TryGetValue(sanitizeKey(identifier), out var value) ? new FormParseNode(value) : null;
public IParseNode? GetChildNode(string identifier) => Fields.TryGetValue(SanitizeKey(identifier), out var value) ? new FormParseNode(value) : null;
/// <inheritdoc/>
public IEnumerable<T> GetCollectionOfObjectValues<T>(ParsableFactory<T> factory) where T : IParsable => throw new InvalidOperationException("collections are not supported with uri form encoding");

Expand Down Expand Up @@ -141,8 +141,7 @@ private void AssignFieldValues<T>(T item) where T : IParsable
IDictionary<string, object>? itemAdditionalData = null;
if(item is IAdditionalDataHolder holder)
{
if(holder.AdditionalData == null)
holder.AdditionalData = new Dictionary<string, object>();
holder.AdditionalData ??= new Dictionary<string, object>();
itemAdditionalData = holder.AdditionalData;
}
var fieldDeserializers = item.GetFieldDeserializers();
Expand Down
15 changes: 10 additions & 5 deletions src/FormSerializationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void WriteBoolValue(string? key, bool? value) {
/// <inheritdoc/>
public void WriteByteArrayValue(string? key, byte[]? value) {
if(value != null)//empty array is meaningful
WriteStringValue(key, value.Any() ? Convert.ToBase64String(value) : string.Empty);
WriteStringValue(key, value.Length > 0 ? Convert.ToBase64String(value) : string.Empty);
}
/// <inheritdoc/>
public void WriteByteValue(string? key, byte? value) {
Expand All @@ -109,7 +109,7 @@ public void WriteByteValue(string? key, byte? value) {
/// <inheritdoc/>
public void WriteCollectionOfPrimitiveValues<T>(string? key, IEnumerable<T>? values)
{
if(values == null || !values.Any()) return;
if(values == null) return;
foreach(var value in values.Where(static x => x != null))
WriteAnyValue(key,value!);
}
Expand Down Expand Up @@ -201,7 +201,7 @@ public void WriteTimeValue(string? key, Time? value) {
}
/// <inheritdoc/>
#if NET5_0_OR_GREATER
public void WriteCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]T>(string? key, IEnumerable<T?>? values) where T : struct, Enum
public void WriteCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(string? key, IEnumerable<T?>? values) where T : struct, Enum
#else
public void WriteCollectionOfEnumValues<T>(string? key, IEnumerable<T?>? values) where T : struct, Enum
#endif
Expand All @@ -212,15 +212,20 @@ public void WriteCollectionOfEnumValues<T>(string? key, IEnumerable<T?>? values)
}
/// <inheritdoc/>
#if NET5_0_OR_GREATER
public void WriteEnumValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]T>(string? key, T? value) where T : struct, Enum
public void WriteEnumValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(string? key, T? value) where T : struct, Enum
#else
public void WriteEnumValue<T>(string? key, T? value) where T : struct, Enum
#endif
{
if(value.HasValue)
{
if(typeof(T).GetCustomAttributes<FlagsAttribute>().Any())
WriteStringValue(key, string.Join(",", Enum.GetValues(typeof(T))
WriteStringValue(key, string.Join(",",
#if NET5_0_OR_GREATER
Enum.GetValues<T>()
#else
Enum.GetValues(typeof(T))
#endif
.Cast<T>()
.Where(x => value.Value.HasFlag(x))
.Select(static x => Enum.GetName(typeof(T),x))
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.1.1</VersionPrefix>
<VersionPrefix>1.1.2</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down

0 comments on commit 1788aaf

Please sign in to comment.