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

Commit

Permalink
Fix IsTrimmable property and found issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hwoodiwiss committed Feb 5, 2024
1 parent db542c1 commit b037aec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Microsoft.Kiota.Serialization.Text.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<NoWarn>$(NoWarn);NU5048;NETSDK1138</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFrameworkVersion)' == 'net5.0'">
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0'">
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

Expand Down
8 changes: 4 additions & 4 deletions src/TextParseNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public TextParseNode(string? text)
/// <inheritdoc />
public Time? GetTimeValue() => DateTime.TryParse(Text, out var result) ? new Time(result) : null;
/// <inheritdoc />
#if NET5_0_OR_GREATER
public IEnumerable<T?> GetCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>() where T : struct, Enum
#if NET5_0_OR_GREATER
public IEnumerable<T?> GetCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>() where T : struct, Enum
#else
public IEnumerable<T?> GetCollectionOfEnumValues<T>() where T : struct, Enum
#endif
=> throw new InvalidOperationException(NoStructuredDataMessage);
/// <inheritdoc />
#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<T>() where T : struct, Enum
#endif
Expand Down
15 changes: 9 additions & 6 deletions src/TextSerializationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace Microsoft.Kiota.Serialization.Text;
/// <summary>
/// The <see cref="ISerializationWriter"/> implementation for text content types.
/// </summary>
public class TextSerializationWriter : ISerializationWriter, IDisposable {
public class TextSerializationWriter : ISerializationWriter, IDisposable
{
private readonly MemoryStream _stream = new MemoryStream();
private readonly StreamWriter _writer;
/// <summary>
Expand Down Expand Up @@ -45,7 +46,8 @@ public void Dispose()
GC.SuppressFinalize(this);
}
/// <inheritdoc />
public Stream GetSerializedContent() {
public Stream GetSerializedContent()
{
_writer.Flush();
_stream.Position = 0;
return _stream;
Expand Down Expand Up @@ -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;
}
Expand All @@ -102,14 +105,14 @@ public void WriteStringValue(string? key, string? value)
/// <inheritdoc />
public void WriteTimeValue(string? key, Time? value) => WriteStringValue(key, value?.ToString());
/// <inheritdoc />
#if NET5_0_OR_GREATER
public void WriteCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(string? key, IEnumerable<T?>? values) where T : struct, Enum
#if NET5_0_OR_GREATER
public void WriteCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] 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
=> throw new InvalidOperationException(TextParseNode.NoStructuredDataMessage);
/// <inheritdoc />
#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<T>(string? key, T? value) where T : struct, Enum
Expand Down

0 comments on commit b037aec

Please sign in to comment.