Skip to content

Commit

Permalink
Add sync HttpClient support (#13722)
Browse files Browse the repository at this point in the history
Fixes: #13476

A lot of nullability fixed because of building against assemblies with annotations.
  • Loading branch information
pakrym authored Nov 24, 2020
1 parent a3be3e8 commit 29a6bd3
Show file tree
Hide file tree
Showing 42 changed files with 774 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public static partial class SerializationExtensions
{
public static System.BinaryData SerializeToBinaryData(this Azure.Core.Serialization.ObjectSerializer serializer, object? value, System.Type? inputType = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.ValueTask<System.BinaryData> SerializeToBinaryDataAsync(this Azure.Core.Serialization.ObjectSerializer serializer, object? value, System.Type? inputType = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.ValueTask<T> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static T ToObject<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.ValueTask<T?> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static T? ToObject<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
}
namespace Azure.Core
Expand All @@ -20,8 +20,8 @@ public DynamicJson(System.Text.Json.JsonElement element) { }
public static Azure.Core.DynamicJson Array(params Azure.Core.DynamicJson[] values) { throw null; }
public static Azure.Core.DynamicJson Array(System.Collections.Generic.IEnumerable<Azure.Core.DynamicJson> values) { throw null; }
public static Azure.Core.DynamicJson Create(System.Text.Json.JsonElement element) { throw null; }
public System.Threading.Tasks.Task<T> DeserializeAsync<T>(Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public T Deserialize<T>(Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public System.Threading.Tasks.Task<T?> DeserializeAsync<T>(Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public T? Deserialize<T>(Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public T Deserialize<T>(System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
public System.Collections.Generic.IEnumerable<Azure.Core.DynamicJson> EnumerateArray() { throw null; }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Azure.Core.DynamicJson>> EnumerateObject() { throw null; }
Expand Down
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>
8 changes: 4 additions & 4 deletions sdk/core/Azure.Core.Experimental/src/DynamicJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,16 @@ public T Deserialize<T>(JsonSerializerOptions? options = null)
return JsonSerializer.Deserialize<T>(ToString(), options);
}

public T Deserialize<T>(ObjectSerializer serializer, CancellationToken cancellationToken = default)
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);
}

public async Task<T> DeserializeAsync<T>(ObjectSerializer serializer, CancellationToken cancellationToken = default)
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 @@ -27,8 +28,8 @@ public static class SerializationExtensions
/// when deserializing the data.</param>
/// <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);
public static T? ToObject<T>(this BinaryData data, ObjectSerializer serializer, CancellationToken cancellationToken = default) =>
(T?)serializer.Deserialize(data.ToStream(), typeof(T), cancellationToken);

/// <summary>
/// Converts the <see cref="BinaryData"/> to the specified type using
Expand All @@ -41,8 +42,8 @@ public static T ToObject<T>(this BinaryData data, ObjectSerializer serializer, C
/// when deserializing the data.</param>
/// <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);
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);

/// <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

0 comments on commit 29a6bd3

Please sign in to comment.