Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile error when Azure SDK is targeting .NET 6. #2245

Merged
merged 18 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/AutoRest.CSharp/AutoRest.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.1.0" />
<PackageReference Include="System.Text.Json" Version="6.0.5" />
<PackageReference Include="YamlDotNet" Version="11.2.1" />
<!-- Any stable version of System.Memory should work here. -->
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

<!-- Enable SourceLink -->
Expand Down
8 changes: 8 additions & 0 deletions src/assets/Generator.Shared/FormUrlEncodedContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ private void BuildIfNeeded ()
public override async Task WriteToAsync(Stream stream, CancellationToken cancellation)
{
BuildIfNeeded ();
#if NET6_0_OR_GREATER
await stream.WriteAsync(_bytes.AsMemory(), cancellation).ConfigureAwait(false);
#else
await stream.WriteAsync(_bytes, 0, _bytes.Length, cancellation).ConfigureAwait(false);
#endif
}

public override void WriteTo(Stream stream, CancellationToken cancellation)
{
BuildIfNeeded ();
#if NET6_0_OR_GREATER
stream.Write(_bytes.AsSpan());
#else
stream.Write(_bytes, 0, _bytes.Length);
#endif
}

public override bool TryComputeLength(out long length)
Expand Down
9 changes: 9 additions & 0 deletions src/assets/Generator.Shared/StringRequestContent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.IO;
using System.Text;
using System.Threading;
Expand All @@ -19,12 +20,20 @@ public StringRequestContent(string value)

public override async Task WriteToAsync(Stream stream, CancellationToken cancellation)
{
#if NET6_0_OR_GREATER
await stream.WriteAsync(_bytes.AsMemory(), cancellation).ConfigureAwait(false);
#else
await stream.WriteAsync(_bytes, 0, _bytes.Length, cancellation).ConfigureAwait(false);
#endif
}

public override void WriteTo(Stream stream, CancellationToken cancellation)
{
#if NET6_0_OR_GREATER
stream.Write(_bytes.AsSpan());
#else
stream.Write(_bytes, 0, _bytes.Length);
#endif
}

public override bool TryComputeLength(out long length)
Expand Down