Skip to content

Commit 1802d31

Browse files
authored
NullableResponse<T> and consumption by tables (#31790)
* NullableResponse<T>
1 parent 7445b52 commit 1802d31

25 files changed

+1331
-76
lines changed

sdk/appconfiguration/Azure.Data.AppConfiguration/src/Azure.Data.AppConfiguration.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
<PackageTags>Microsoft Azure Application Configuration;Data;AppConfig;$(PackageCommonTags)</PackageTags>
1010
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
1111
<NoWarn>$(NoWarn);3021;AZC0007;AZC0006</NoWarn>
12-
<IncludeOperationsSharedSource>true</IncludeOperationsSharedSource>
12+
<IncludeOperationsSharedSource>true</IncludeOperationsSharedSource>
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Azure.Core" />
16+
<!-- <PackageReference Include="Azure.Core" /> -->
17+
<ProjectReference Include="..\..\..\core\Azure.Core\src\Azure.Core.csproj" />
1718
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
1819
<PackageReference Include="System.Text.Json" />
1920
</ItemGroup>

sdk/core/Azure.Core/CHANGELOG.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.26.0-beta.1 (Unreleased)
44

55
### Features Added
6+
- Introduced a new `NullableResponse<T>` type for scenarios where a service method may or may not return a value. One common example is `Get*IfExists` methods. `Response<T>` also now inherits from `NullableResponse<T>`.
67

78
### Breaking Changes
89

@@ -15,7 +16,7 @@
1516
### Features Added
1617
- Added `RequestFailedDetailsParser` abstract class, which client libraries can implement to control customization of exception messages for failed responses.
1718
- Added `HttpPipelineOptions` type which is accepted in a new overload to `HttpPipelineBuilder.Build`. This type contains all the properties from other overloads and adds a property to specify a `RequestFailedDetailsParser`.
18-
- Added a property to `HttpPipelineTransportOptions` called `ClientCertificates` which is a collection of `X509Certificate2`. If populated, the certificates in the collection will be used by the client for TLS client certificate authentication.
19+
- Added a property to `HttpPipelineTransportOptions` called `ClientCertificates` which is a collection of `X509Certificate2`. If populated, the certificates in the collection will be used by the client for TLS client certificate authentication.
1920
- Added the `MultipartResponse` type, which can be used by clients to parse the sub-responses for multi-part responses.
2021

2122
## 1.24.0 (2022-04-04)
@@ -56,7 +57,7 @@
5657
- Added `ResourceIdentifier`. This class allows users to load an Azure resource identifier string and parse out the pieces of that string such as which `SubscriptionId` does the resource belong to.
5758
- Added `ResourceType`. This class represents the ARM provider information for a given resource and is used by the `ResourceIdentifier` class.
5859
- Added `HttpPipelineTransportOptions` type. This type contains a `ServerCertificateCustomValidationCallback` property that allows callers to set a `Func<ServerCertificateCustomValidationArgs, bool>` delegate. If set, the delegate will be called to validate the server side TLS certificate.
59-
- Added a new static overload for `HttpPipelineBuilder.Build` that takes an `HttpPipelineTransportOptions` instance. This overload creates an `HttpPipeline` with the default transport configuration and the `HttpPipelineTransportOptions` applied. It returns a `DisposableHttpPipeline` that implements `IDisposable`. Note: The `HttpPipelineTransportOptions` will not be applied if a custom `Transport` has been set in the `ClientOptions`. In the case that transport options were provided but not applied, an event is logged `(PipelineTransportOptionsNotApplied`).
60+
- Added a new static overload for `HttpPipelineBuilder.Build` that takes an `HttpPipelineTransportOptions` instance. This overload creates an `HttpPipeline` with the default transport configuration and the `HttpPipelineTransportOptions` applied. It returns a `DisposableHttpPipeline` that implements `IDisposable`. Note: The `HttpPipelineTransportOptions` will not be applied if a custom `Transport` has been set in the `ClientOptions`. In the case that transport options were provided but not applied, an event is logged `(PipelineTransportOptionsNotApplied`).
6061

6162
### Breaking Changes
6263

@@ -191,7 +192,7 @@ options.Diagnostics.LoggedQueryParameters.Remove("api-version");
191192
- `AzureSasCredential` and its respective policy.
192193

193194
### Key Bug Fixes
194-
- Avoid a causing and ignoring an exception when setting network stream timeout on .NET Core
195+
- Avoid a causing and ignoring an exception when setting network stream timeout on .NET Core.
195196

196197
## 1.7.0 (2020-12-14)
197198

@@ -215,7 +216,7 @@ options.Diagnostics.LoggedQueryParameters.Remove("api-version");
215216
## 1.5.1 (2020-10-01)
216217

217218
### Changed
218-
- `ServicePointManager` Connection limit is automatically increased to `50` for Azure endpoints.
219+
- `ServicePointManager` Connection limit is automatically increased to `50` for Azure endpoints.
219220

220221

221222
## 1.5.0 (2020-09-03)
@@ -229,7 +230,7 @@ options.Diagnostics.LoggedQueryParameters.Remove("api-version");
229230
```xml
230231
<ItemGroup>
231232
<RuntimeHostConfigurationOption Include="Azure.Core.Pipeline.DisableHttpWebRequestTransport" Value="true" />
232-
</ItemGroup>
233+
</ItemGroup>
233234
```
234235

235236
When the environment variable or the switch are set the `HttpClientTransport` would be used by default instead.
@@ -290,28 +291,28 @@ When the environment variable or the switch are set the `HttpClientTransport` wo
290291
- Add support for retrying on 408, 500, 502, 504 status codes.
291292
- Remove commit hash from User-Agent telemetry.
292293

293-
## 1.0.1
294+
## 1.0.1
294295

295296
- Fix issues with log redaction where first query character was replaced with '?' character.
296297
- Exclude EventCounter events from AzureEventSourceListener.
297298
- Add `AZURE_TRACING_DISABLED` environment variable support.
298299

299-
## 1.0.0
300+
## 1.0.0
300301

301302
- Updating versioning and packaging for general availability.
302303
- Make types and namespace names consistent.
303304

304-
## 1.0.0-preview.9
305+
## 1.0.0-preview.9
305306

306307
- Added console and trace logger listener.
307308
- Added additional content and header logging options.
308309
- Moved commonly used types to Azure namespace.
309310

310-
## 1.0.0-preview.8
311+
## 1.0.0-preview.8
311312

312313
- Minor improvements and bug fixes.
313314

314-
## 1.0.0-preview.7
315+
## 1.0.0-preview.7
315316

316317
- Support for distributed tracing added.
317318
- Support for TokenCredential in ASP.NET Core integration added.

sdk/core/Azure.Core/api/Azure.Core.net461.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ public MatchConditions() { }
113113
public Azure.ETag? IfMatch { get { throw null; } set { } }
114114
public Azure.ETag? IfNoneMatch { get { throw null; } set { } }
115115
}
116+
public abstract partial class NullableResponse<T>
117+
{
118+
protected NullableResponse() { }
119+
public abstract bool HasValue { get; }
120+
public abstract T Value { get; }
121+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
122+
public override bool Equals(object? obj) { throw null; }
123+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
124+
public override int GetHashCode() { throw null; }
125+
public abstract Azure.Response GetRawResponse();
126+
public override string ToString() { throw null; }
127+
}
116128
public abstract partial class Operation
117129
{
118130
protected Operation() { }
@@ -239,17 +251,16 @@ public ResponseError(string? code, string? message) { }
239251
public string? Message { get { throw null; } }
240252
public override string ToString() { throw null; }
241253
}
242-
public abstract partial class Response<T>
254+
public abstract partial class Response<T> : Azure.NullableResponse<T>
243255
{
244256
protected Response() { }
245-
public abstract T Value { get; }
257+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
258+
public override bool HasValue { get { throw null; } }
246259
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
247260
public override bool Equals(object? obj) { throw null; }
248261
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
249262
public override int GetHashCode() { throw null; }
250-
public abstract Azure.Response GetRawResponse();
251263
public static implicit operator T (Azure.Response<T> response) { throw null; }
252-
public override string ToString() { throw null; }
253264
}
254265
public partial class SyncAsyncEventArgs : System.EventArgs
255266
{

sdk/core/Azure.Core/api/Azure.Core.net5.0.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ public MatchConditions() { }
113113
public Azure.ETag? IfMatch { get { throw null; } set { } }
114114
public Azure.ETag? IfNoneMatch { get { throw null; } set { } }
115115
}
116+
public abstract partial class NullableResponse<T>
117+
{
118+
protected NullableResponse() { }
119+
public abstract bool HasValue { get; }
120+
public abstract T Value { get; }
121+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
122+
public override bool Equals(object? obj) { throw null; }
123+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
124+
public override int GetHashCode() { throw null; }
125+
public abstract Azure.Response GetRawResponse();
126+
public override string ToString() { throw null; }
127+
}
116128
public abstract partial class Operation
117129
{
118130
protected Operation() { }
@@ -239,17 +251,16 @@ public ResponseError(string? code, string? message) { }
239251
public string? Message { get { throw null; } }
240252
public override string ToString() { throw null; }
241253
}
242-
public abstract partial class Response<T>
254+
public abstract partial class Response<T> : Azure.NullableResponse<T>
243255
{
244256
protected Response() { }
245-
public abstract T Value { get; }
257+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
258+
public override bool HasValue { get { throw null; } }
246259
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
247260
public override bool Equals(object? obj) { throw null; }
248261
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
249262
public override int GetHashCode() { throw null; }
250-
public abstract Azure.Response GetRawResponse();
251263
public static implicit operator T (Azure.Response<T> response) { throw null; }
252-
public override string ToString() { throw null; }
253264
}
254265
public partial class SyncAsyncEventArgs : System.EventArgs
255266
{

sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ public MatchConditions() { }
113113
public Azure.ETag? IfMatch { get { throw null; } set { } }
114114
public Azure.ETag? IfNoneMatch { get { throw null; } set { } }
115115
}
116+
public abstract partial class NullableResponse<T>
117+
{
118+
protected NullableResponse() { }
119+
public abstract bool HasValue { get; }
120+
public abstract T Value { get; }
121+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
122+
public override bool Equals(object? obj) { throw null; }
123+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
124+
public override int GetHashCode() { throw null; }
125+
public abstract Azure.Response GetRawResponse();
126+
public override string ToString() { throw null; }
127+
}
116128
public abstract partial class Operation
117129
{
118130
protected Operation() { }
@@ -239,17 +251,16 @@ public ResponseError(string? code, string? message) { }
239251
public string? Message { get { throw null; } }
240252
public override string ToString() { throw null; }
241253
}
242-
public abstract partial class Response<T>
254+
public abstract partial class Response<T> : Azure.NullableResponse<T>
243255
{
244256
protected Response() { }
245-
public abstract T Value { get; }
257+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
258+
public override bool HasValue { get { throw null; } }
246259
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
247260
public override bool Equals(object? obj) { throw null; }
248261
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
249262
public override int GetHashCode() { throw null; }
250-
public abstract Azure.Response GetRawResponse();
251263
public static implicit operator T (Azure.Response<T> response) { throw null; }
252-
public override string ToString() { throw null; }
253264
}
254265
public partial class SyncAsyncEventArgs : System.EventArgs
255266
{

sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ public MatchConditions() { }
113113
public Azure.ETag? IfMatch { get { throw null; } set { } }
114114
public Azure.ETag? IfNoneMatch { get { throw null; } set { } }
115115
}
116+
public abstract partial class NullableResponse<T>
117+
{
118+
protected NullableResponse() { }
119+
public abstract bool HasValue { get; }
120+
public abstract T Value { get; }
121+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
122+
public override bool Equals(object? obj) { throw null; }
123+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
124+
public override int GetHashCode() { throw null; }
125+
public abstract Azure.Response GetRawResponse();
126+
public override string ToString() { throw null; }
127+
}
116128
public abstract partial class Operation
117129
{
118130
protected Operation() { }
@@ -239,17 +251,16 @@ public ResponseError(string? code, string? message) { }
239251
public string? Message { get { throw null; } }
240252
public override string ToString() { throw null; }
241253
}
242-
public abstract partial class Response<T>
254+
public abstract partial class Response<T> : Azure.NullableResponse<T>
243255
{
244256
protected Response() { }
245-
public abstract T Value { get; }
257+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
258+
public override bool HasValue { get { throw null; } }
246259
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
247260
public override bool Equals(object? obj) { throw null; }
248261
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
249262
public override int GetHashCode() { throw null; }
250-
public abstract Azure.Response GetRawResponse();
251263
public static implicit operator T (Azure.Response<T> response) { throw null; }
252-
public override string ToString() { throw null; }
253264
}
254265
public partial class SyncAsyncEventArgs : System.EventArgs
255266
{
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.ComponentModel;
5+
6+
namespace Azure
7+
{
8+
/// <summary>
9+
/// Represents a result of Azure operation.
10+
/// </summary>
11+
/// <typeparam name="T">The type of returned value.</typeparam>
12+
#pragma warning disable SA1649 // File name should match first type name
13+
public abstract class NullableResponse<T>
14+
#pragma warning restore SA1649 // File name should match first type name
15+
{
16+
private const string NoValue = "<null>";
17+
18+
/// <summary>
19+
/// Gets a value indicating whether the current instance has a valid value of its underlying type.
20+
/// </summary>
21+
public abstract bool HasValue { get; }
22+
23+
/// <summary>
24+
/// Gets the value returned by the service. Accessing this property will throw if <see cref="HasValue"/> is false.
25+
/// </summary>
26+
public abstract T Value { get; }
27+
28+
/// <summary>
29+
/// Returns the HTTP response returned by the service.
30+
/// </summary>
31+
/// <returns>The HTTP response returned by the service.</returns>
32+
public abstract Response GetRawResponse();
33+
34+
/// <inheritdoc />
35+
[EditorBrowsable(EditorBrowsableState.Never)]
36+
public override bool Equals(object? obj) => base.Equals(obj);
37+
38+
/// <inheritdoc />
39+
[EditorBrowsable(EditorBrowsableState.Never)]
40+
public override int GetHashCode() => base.GetHashCode();
41+
42+
/// <inheritdoc />
43+
public override string ToString() => $"Status: {GetRawResponse()?.Status}, Value: {(HasValue ? Value : NoValue)}";
44+
}
45+
}

sdk/core/Azure.Core/src/ResponseOfT.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,13 @@ namespace Azure
1414
[DebuggerTypeProxy(typeof(ResponseDebugView<>))]
1515
#pragma warning disable SA1649 // File name should match first type name
1616
#pragma warning disable AZC0012 // Avoid single word type names
17-
public abstract class Response<T>
17+
public abstract class Response<T> : NullableResponse<T>
1818
#pragma warning restore AZC0012 // Avoid single word type names
1919
#pragma warning restore SA1649 // File name should match first type name
2020
{
21-
/// <summary>
22-
/// Returns the HTTP response returned by the service.
23-
/// </summary>
24-
/// <returns>The HTTP response returned by the service.</returns>
25-
public abstract Response GetRawResponse();
26-
27-
/// <summary>
28-
/// Gets the value returned by the service.
29-
/// </summary>
30-
public abstract T Value { get; }
21+
/// <inheritdoc />
22+
[EditorBrowsable(EditorBrowsableState.Never)]
23+
public override bool HasValue => true;
3124

3225
/// <summary>
3326
/// Returns the value of this <see cref="Response{T}"/> object.
@@ -52,11 +45,5 @@ public static implicit operator T(Response<T> response)
5245
/// <inheritdoc />
5346
[EditorBrowsable(EditorBrowsableState.Never)]
5447
public override int GetHashCode() => base.GetHashCode();
55-
56-
/// <inheritdoc />
57-
public override string ToString()
58-
{
59-
return $"Status: {GetRawResponse().Status}, Value: {Value}";
60-
}
6148
}
6249
}

sdk/core/Azure.Core/src/Shared/NoBodyResponseOfT.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace Azure
77
{
8+
/// <summary>
9+
/// NOTE: This type should not be used going forward. Use NoValueResponse{T} instead.
10+
/// </summary>
811
#pragma warning disable SA1649 // File name should match first type name
912
internal class NoBodyResponse<T> : Response<T>
1013
#pragma warning restore SA1649 // File name should match first type name
@@ -16,6 +19,9 @@ public NoBodyResponse(Response response)
1619
_response = response;
1720
}
1821

22+
/// <inheritdoc />
23+
public override bool HasValue => false;
24+
1925
public override T Value
2026
{
2127
get

0 commit comments

Comments
 (0)