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 #140 from hwoodiwiss/hwoodiwiss-fix-is-trimmable
Browse files Browse the repository at this point in the history
Fix IsTrimmable property
  • Loading branch information
andrueastman authored Feb 5, 2024
2 parents db542c1 + 92cd8b2 commit 1547d59
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# JetBrains Rider
.idea/
4 changes: 2 additions & 2 deletions src/Microsoft.Kiota.Serialization.Text.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<NoWarn>$(NoWarn);NU5048;NETSDK1138</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFrameworkVersion)' == 'net5.0'">
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0'">
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.7.8" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.7.9" />
</ItemGroup>

<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
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;

Check warning on line 67 in src/TextParseNode.cs

View workflow job for this annotation

GitHub Actions / Build

Use a format provider when parsing date and time. (https://rules.sonarsource.com/csharp/RSPEC-6580)

Check warning on line 67 in src/TextParseNode.cs

View workflow job for this annotation

GitHub Actions / Build

Use a format provider when parsing date and time. (https://rules.sonarsource.com/csharp/RSPEC-6580)
/// <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
13 changes: 8 additions & 5 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

Check warning on line 18 in src/TextSerializationWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Fix this implementation of 'IDisposable' to conform to the dispose pattern. (https://rules.sonarsource.com/csharp/RSPEC-3881)

Check warning on line 18 in src/TextSerializationWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Fix this implementation of 'IDisposable' to conform to the dispose pattern. (https://rules.sonarsource.com/csharp/RSPEC-3881)

Check warning on line 18 in src/TextSerializationWriter.cs

View workflow job for this annotation

GitHub Actions / Build

'ISerializationWriter' implements 'IDisposable' so 'IDisposable' can be removed from the inheritance list. (https://rules.sonarsource.com/csharp/RSPEC-1939)

Check warning on line 18 in src/TextSerializationWriter.cs

View workflow job for this annotation

GitHub Actions / Build

'ISerializationWriter' implements 'IDisposable' so 'IDisposable' can be removed from the inheritance list. (https://rules.sonarsource.com/csharp/RSPEC-1939)
{
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
#if NET5_0_OR_GREATER
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
=> 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 1547d59

Please sign in to comment.