-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
NullableResponseOfT.cs
45 lines (37 loc) · 1.61 KB
/
NullableResponseOfT.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.ComponentModel;
namespace Azure
{
/// <summary>
/// Represents a result of Azure operation.
/// </summary>
/// <typeparam name="T">The type of returned value.</typeparam>
#pragma warning disable SA1649 // File name should match first type name
public abstract class NullableResponse<T>
#pragma warning restore SA1649 // File name should match first type name
{
private const string NoValue = "<null>";
/// <summary>
/// Gets a value indicating whether the current instance has a valid value of its underlying type.
/// </summary>
public abstract bool HasValue { get; }
/// <summary>
/// Gets the value returned by the service. Accessing this property will throw if <see cref="HasValue"/> is false.
/// </summary>
public abstract T? Value { get; }
/// <summary>
/// Returns the HTTP response returned by the service.
/// </summary>
/// <returns>The HTTP response returned by the service.</returns>
public abstract Response GetRawResponse();
/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object? obj) => base.Equals(obj);
/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => base.GetHashCode();
/// <inheritdoc />
public override string ToString() => $"Status: {GetRawResponse()?.Status}, Value: {(HasValue ? Value : NoValue)}";
}
}