From b037aecd383d78b3f1d5ac90bf296ba122d89cee Mon Sep 17 00:00:00 2001 From: Hugo Woodiwiss Date: Sun, 4 Feb 2024 11:09:12 +0000 Subject: [PATCH 1/4] Fix IsTrimmable property and found issues --- src/Microsoft.Kiota.Serialization.Text.csproj | 2 +- src/TextParseNode.cs | 8 ++++---- src/TextSerializationWriter.cs | 15 +++++++++------ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.Kiota.Serialization.Text.csproj b/src/Microsoft.Kiota.Serialization.Text.csproj index 360537d..016fefa 100644 --- a/src/Microsoft.Kiota.Serialization.Text.csproj +++ b/src/Microsoft.Kiota.Serialization.Text.csproj @@ -33,7 +33,7 @@ README.md $(NoWarn);NU5048;NETSDK1138 - + true diff --git a/src/TextParseNode.cs b/src/TextParseNode.cs index 7dd0f17..63353de 100644 --- a/src/TextParseNode.cs +++ b/src/TextParseNode.cs @@ -66,15 +66,15 @@ public TextParseNode(string? text) /// public Time? GetTimeValue() => DateTime.TryParse(Text, out var result) ? new Time(result) : null; /// - #if NET5_0_OR_GREATER - public IEnumerable GetCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>() where T : struct, Enum +#if NET5_0_OR_GREATER + public IEnumerable GetCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>() where T : struct, Enum #else public IEnumerable GetCollectionOfEnumValues() where T : struct, Enum #endif => throw new InvalidOperationException(NoStructuredDataMessage); /// - #if NET5_0_OR_GREATER - public T? GetEnumValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>() where T : struct, Enum +#if NET5_0_OR_GREATER + public T? GetEnumValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>() where T : struct, Enum #else public T? GetEnumValue() where T : struct, Enum #endif diff --git a/src/TextSerializationWriter.cs b/src/TextSerializationWriter.cs index 57ae6b7..6d8c966 100644 --- a/src/TextSerializationWriter.cs +++ b/src/TextSerializationWriter.cs @@ -15,7 +15,8 @@ namespace Microsoft.Kiota.Serialization.Text; /// /// The implementation for text content types. /// -public class TextSerializationWriter : ISerializationWriter, IDisposable { +public class TextSerializationWriter : ISerializationWriter, IDisposable +{ private readonly MemoryStream _stream = new MemoryStream(); private readonly StreamWriter _writer; /// @@ -45,7 +46,8 @@ public void Dispose() GC.SuppressFinalize(this); } /// - public Stream GetSerializedContent() { + public Stream GetSerializedContent() + { _writer.Flush(); _stream.Position = 0; return _stream; @@ -92,7 +94,8 @@ public void WriteStringValue(string? key, string? value) if(!string.IsNullOrEmpty(value)) if(_written) throw new InvalidOperationException("a value was already written for this serialization writer, text content only supports a single value"); - else { + else + { _writer.Write(value); _written = true; } @@ -102,14 +105,14 @@ public void WriteStringValue(string? key, string? value) /// public void WriteTimeValue(string? key, Time? value) => WriteStringValue(key, value?.ToString()); /// - #if NET5_0_OR_GREATER - public void WriteCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(string? key, IEnumerable? values) where T : struct, Enum +#if NET5_0_OR_GREATER + public void WriteCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(string? key, IEnumerable? values) where T : struct, Enum #else public void WriteCollectionOfEnumValues(string? key, IEnumerable? values) where T : struct, Enum #endif => throw new InvalidOperationException(TextParseNode.NoStructuredDataMessage); /// - #if NET5_0_OR_GREATER +#if NET5_0_OR_GREATER public void WriteEnumValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(string? key, T? value) where T : struct, Enum #else public void WriteEnumValue(string? key, T? value) where T : struct, Enum From 4e5524fcedf9ea987d493763d543bb8c7426aa91 Mon Sep 17 00:00:00 2001 From: Hugo Woodiwiss Date: Sun, 4 Feb 2024 11:32:09 +0000 Subject: [PATCH 2/4] Add gitignore for rider --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index dfcfd56..aea9645 100644 --- a/.gitignore +++ b/.gitignore @@ -348,3 +348,6 @@ MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ + +# JetBrains Rider +.idea/ \ No newline at end of file From e752f6c4ec2e3191cd8824ccb207727d4579d6b1 Mon Sep 17 00:00:00 2001 From: Hugo Woodiwiss Date: Mon, 5 Feb 2024 09:12:52 +0000 Subject: [PATCH 3/4] Undo DAM change now that abstractions are updated --- src/TextSerializationWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TextSerializationWriter.cs b/src/TextSerializationWriter.cs index 6d8c966..ba9f2c4 100644 --- a/src/TextSerializationWriter.cs +++ b/src/TextSerializationWriter.cs @@ -106,7 +106,7 @@ public void WriteStringValue(string? key, string? value) public void WriteTimeValue(string? key, Time? value) => WriteStringValue(key, value?.ToString()); /// #if NET5_0_OR_GREATER - public void WriteCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(string? key, IEnumerable? values) where T : struct, Enum + public void WriteCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(string? key, IEnumerable? values) where T : struct, Enum #else public void WriteCollectionOfEnumValues(string? key, IEnumerable? values) where T : struct, Enum #endif From 92cd8b22dd6b60476ce75d6065118a11e3d2f443 Mon Sep 17 00:00:00 2001 From: Hugo Woodiwiss Date: Mon, 5 Feb 2024 09:13:10 +0000 Subject: [PATCH 4/4] Bump abstractions to latest --- src/Microsoft.Kiota.Serialization.Text.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Kiota.Serialization.Text.csproj b/src/Microsoft.Kiota.Serialization.Text.csproj index 016fefa..590bfd1 100644 --- a/src/Microsoft.Kiota.Serialization.Text.csproj +++ b/src/Microsoft.Kiota.Serialization.Text.csproj @@ -39,7 +39,7 @@ - +