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

Add sync HttpClient support #13722

Merged
21 commits merged into from
Nov 24, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
<Compile Include="$(AzureCoreSharedSources)Argument.cs" />
<Compile Include="$(AzureCoreSharedSources)HashCodeBuilder.cs" />
<Compile Include="$(AzureCoreSharedSources)TaskExtensions.cs" />
<Compile Include="$(AzureCoreSharedSources)NullableAttributes.cs" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions sdk/core/Azure.Core.Experimental/src/DynamicJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,13 @@ public T Deserialize<T>(JsonSerializerOptions? options = null)
public T Deserialize<T>(ObjectSerializer serializer, CancellationToken cancellationToken = default)
{
var stream = new MemoryStream(Encoding.UTF8.GetBytes(ToString()));
return (T) serializer.Deserialize(stream, typeof(T), cancellationToken);
return (T)serializer.Deserialize(stream, typeof(T), cancellationToken)!;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this strictly true, though? ToString() could (though shouldn't) return null. Is that guarded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the return type to nullable.

}

public async Task<T> DeserializeAsync<T>(ObjectSerializer serializer, CancellationToken cancellationToken = default)
{
var stream = new MemoryStream(Encoding.UTF8.GetBytes(ToString()));
return (T) await serializer.DeserializeAsync(stream, typeof(T), cancellationToken).ConfigureAwait(false);
return (T)(await serializer.DeserializeAsync(stream, typeof(T), cancellationToken).ConfigureAwait(false))!;
}

private struct Number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -28,7 +29,7 @@ public static class SerializationExtensions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use during deserialization.</param>
///<returns>The data converted to the specified type.</returns>
public static T ToObject<T>(this BinaryData data, ObjectSerializer serializer, CancellationToken cancellationToken = default) =>
(T)serializer.Deserialize(data.ToStream(), typeof(T), cancellationToken);
(T)serializer.Deserialize(data.ToStream(), typeof(T), cancellationToken)!;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment applies to these changed lines in this file. Also, given this is a fully-public API, we should probably be checking parameters here; though, I'm on the side of not checking the this parameter since an NRE would be thrown, which is what happened if an instance method was called on this anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the return type to nullable.

cc @JoshLove-msft if he wants to file an issue for argument checking.


/// <summary>
/// Converts the <see cref="BinaryData"/> to the specified type using
Expand All @@ -42,7 +43,7 @@ public static T ToObject<T>(this BinaryData data, ObjectSerializer serializer, C
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use during deserialization.</param>
///<returns>The data converted to the specified type.</returns>
public static async ValueTask<T> ToObjectAsync<T>(this BinaryData data, ObjectSerializer serializer, CancellationToken cancellationToken = default) =>
(T)await serializer.DeserializeAsync(data.ToStream(), typeof(T), cancellationToken).ConfigureAwait(false);
(T)(await serializer.DeserializeAsync(data.ToStream(), typeof(T), cancellationToken).ConfigureAwait(false))!;

/// <summary>
/// Convert the provided value to it's binary representation and return it as a <see cref="BinaryData"/> instance.
Expand Down
20 changes: 10 additions & 10 deletions sdk/core/Azure.Core/api/Azure.Core.net461.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected AsyncPageable(System.Threading.CancellationToken cancellationToken) {
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override string ToString() { throw null; }
public override string? ToString() { throw null; }
}
public partial class AzureKeyCredential
{
Expand Down Expand Up @@ -87,12 +87,12 @@ protected Operation() { }
public abstract string Id { get; }
public abstract T Value { get; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
public override bool Equals(object? obj) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
public abstract Azure.Response GetRawResponse();
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override string ToString() { throw null; }
public override string? ToString() { throw null; }
public abstract Azure.Response UpdateStatus(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
public abstract System.Threading.Tasks.ValueTask<Azure.Response> UpdateStatusAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
public abstract System.Threading.Tasks.ValueTask<Azure.Response<T>> WaitForCompletionAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
Expand All @@ -112,7 +112,7 @@ protected Pageable(System.Threading.CancellationToken cancellationToken) { }
public override int GetHashCode() { throw null; }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override string ToString() { throw null; }
public override string? ToString() { throw null; }
}
public abstract partial class Page<T>
{
Expand All @@ -126,7 +126,7 @@ protected Page() { }
public override int GetHashCode() { throw null; }
public abstract Azure.Response GetRawResponse();
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override string ToString() { throw null; }
public override string? ToString() { throw null; }
}
public partial class RequestConditions : Azure.MatchConditions
{
Expand Down Expand Up @@ -200,7 +200,7 @@ public void AddPolicy(Azure.Core.Pipeline.HttpPipelinePolicy policy, Azure.Core.
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override string ToString() { throw null; }
public override string? ToString() { throw null; }
}
public partial class DiagnosticsOptions
{
Expand Down Expand Up @@ -532,16 +532,16 @@ public partial class JsonObjectSerializer : Azure.Core.Serialization.ObjectSeria
public JsonObjectSerializer() { }
public JsonObjectSerializer(System.Text.Json.JsonSerializerOptions options) { }
string? Azure.Core.Serialization.IMemberNameConverter.ConvertMemberName(System.Reflection.MemberInfo member) { throw null; }
public override object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; }
public override System.Threading.Tasks.ValueTask<object> DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; }
public override object? Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; }
public override System.Threading.Tasks.ValueTask<object?> DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken) { throw null; }
public override void Serialize(System.IO.Stream stream, object? value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { }
public override System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object? value, System.Type inputType, System.Threading.CancellationToken cancellationToken) { throw null; }
}
public abstract partial class ObjectSerializer
{
protected ObjectSerializer() { }
public abstract object Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken);
public abstract System.Threading.Tasks.ValueTask<object> DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken);
public abstract object? Deserialize(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken);
public abstract System.Threading.Tasks.ValueTask<object?> DeserializeAsync(System.IO.Stream stream, System.Type returnType, System.Threading.CancellationToken cancellationToken);
public abstract void Serialize(System.IO.Stream stream, object? value, System.Type inputType, System.Threading.CancellationToken cancellationToken);
public abstract System.Threading.Tasks.ValueTask SerializeAsync(System.IO.Stream stream, object? value, System.Type inputType, System.Threading.CancellationToken cancellationToken);
}
Expand Down
Loading