From aa93a9880dc886c6f16d3a6d7fef6df0a0c14e44 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Wed, 3 Feb 2021 16:50:56 -0800 Subject: [PATCH 1/2] [Core.Experimental] Improvements for Protocol Clients - Add a ProtocolClientOptions type for use by clients which have no additional options. This means we don't have to generate a type per client - Add a zero argument constructor to `DynamicJson` that behaves like DynamicJson.Object(), since we expect that `DynamicJson` will appear in API signatures and users will want to be able to `new` up the type. --- .../api/Azure.Core.Experimental.netstandard2.0.cs | 5 +++++ .../Azure.Core.Experimental/src/DynamicJson.cs | 7 +++++++ .../src/ProtocolClientOptions.cs | 14 ++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 sdk/core/Azure.Core.Experimental/src/ProtocolClientOptions.cs diff --git a/sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.netstandard2.0.cs b/sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.netstandard2.0.cs index b844ac2d1a80..737d80bccd1e 100644 --- a/sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.netstandard2.0.cs +++ b/sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.netstandard2.0.cs @@ -11,6 +11,7 @@ public override void WriteTo(System.IO.Stream stream, System.Threading.Cancellat } public partial class DynamicJson : System.Dynamic.IDynamicMetaObjectProvider { + public DynamicJson() { } public DynamicJson(string json) { } public DynamicJson(System.Text.Json.JsonElement element) { } public Azure.Core.DynamicJson this[int arrayIndex] { get { throw null; } set { } } @@ -99,6 +100,10 @@ protected virtual void Dispose(bool disposing) { } protected override bool TryGetHeader(string name, out string? value) { throw null; } protected override bool TryGetHeaderValues(string name, out System.Collections.Generic.IEnumerable? values) { throw null; } } + public partial class ProtocolClientOptions : Azure.Core.ClientOptions + { + public ProtocolClientOptions() { } + } } namespace Azure.Core.GeoJson { diff --git a/sdk/core/Azure.Core.Experimental/src/DynamicJson.cs b/sdk/core/Azure.Core.Experimental/src/DynamicJson.cs index 95d82e924305..58d992aebf64 100644 --- a/sdk/core/Azure.Core.Experimental/src/DynamicJson.cs +++ b/sdk/core/Azure.Core.Experimental/src/DynamicJson.cs @@ -29,6 +29,13 @@ public class DynamicJson : IDynamicMetaObjectProvider private List? _arrayRepresentation; private object? _value; + /// + /// Construcs a new DynamicJson which represents an empty JSON object. + /// + public DynamicJson() : this(System.Array.Empty>()) + { + } + public DynamicJson(string json): this(JsonDocument.Parse(json).RootElement) { } diff --git a/sdk/core/Azure.Core.Experimental/src/ProtocolClientOptions.cs b/sdk/core/Azure.Core.Experimental/src/ProtocolClientOptions.cs new file mode 100644 index 000000000000..6e4b5d5a947c --- /dev/null +++ b/sdk/core/Azure.Core.Experimental/src/ProtocolClientOptions.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Core +{ + /// + /// A concrete ClientOptions for use by client with no additonal options other than the common ones. + /// +#pragma warning disable AZC0008 // ClientOptions should have a nested enum called ServiceVersion + public class ProtocolClientOptions : ClientOptions +#pragma warning restore AZC0008 // ClientOptions should have a nested enum called ServiceVersion + { + } +} From 10d83c4b253191c260d793b951c82cf6e94a7870 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Fri, 5 Feb 2021 11:05:36 -0800 Subject: [PATCH 2/2] Add Test --- .../Azure.Core.Experimental/tests/DynamicJsonTest.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sdk/core/Azure.Core.Experimental/tests/DynamicJsonTest.cs b/sdk/core/Azure.Core.Experimental/tests/DynamicJsonTest.cs index 711075916554..8e2178c6f514 100644 --- a/sdk/core/Azure.Core.Experimental/tests/DynamicJsonTest.cs +++ b/sdk/core/Azure.Core.Experimental/tests/DynamicJsonTest.cs @@ -2,7 +2,7 @@ // Licensed under the MIT License. using System; -using System.Collections.Generic; +using System.Linq; using System.Text.Json; using NUnit.Framework; @@ -10,6 +10,14 @@ namespace Azure.Core.Tests { public class DynamicJsonTest { + [Test] + public void DefaultConstructorMakesEmptyObject() + { + var dynamicJson = new DynamicJson(); + + Assert.AreEqual(0, dynamicJson.EnumerateObject().Count()); + } + [Test] public void CanCreateFromJson() {