From fc6a092372cb135b212d4a3c960e0f7c4d6fda66 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Fri, 6 May 2022 14:17:26 -0700 Subject: [PATCH] Enable public api check [OpenTelemetry.Extensions.PersistentStorage.Abstractions] (#337) * enable public api check * clscompliant false * resolve PR comments * add missing api dec * resolve PR comments * minor clean up Co-authored-by: Cijo Thomas --- .../.publicApi/net462/PublicAPI.Shipped.txt | 1 + .../.publicApi/net462/PublicAPI.Unshipped.txt | 20 +++++++++++ .../.publicApi/net6.0/PublicAPI.Shipped.txt | 1 + .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 20 +++++++++++ .../netstandard2.0/PublicAPI.Shipped.txt | 1 + .../netstandard2.0/PublicAPI.Unshipped.txt | 20 +++++++++++ .../AssemblyInfo.cs | 19 +++++++++++ .../NotNullWhenAttribute.cs | 33 +++++++++++++++++++ ...ions.PersistentStorage.Abstractions.csproj | 4 +++ .../PersistentBlob.cs | 13 ++++++-- .../PersistentBlobProvider.cs | 21 ++++++++---- 11 files changed, 145 insertions(+), 8 deletions(-) create mode 100644 src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net462/PublicAPI.Shipped.txt create mode 100644 src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net462/PublicAPI.Unshipped.txt create mode 100644 src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net6.0/PublicAPI.Shipped.txt create mode 100644 src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net6.0/PublicAPI.Unshipped.txt create mode 100644 src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/netstandard2.0/PublicAPI.Shipped.txt create mode 100644 src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt create mode 100644 src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/AssemblyInfo.cs create mode 100644 src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/NotNullWhenAttribute.cs diff --git a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net462/PublicAPI.Shipped.txt b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net462/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net462/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net462/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..5fa88c4d7b --- /dev/null +++ b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net462/PublicAPI.Unshipped.txt @@ -0,0 +1,20 @@ +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryDelete() -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryLease(int leasePeriodMilliseconds) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryRead(out byte[]? buffer) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable! +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.PersistentBlob() -> void +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryDelete() -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryLease(int leasePeriodMilliseconds) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryRead(out byte[]? buffer) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.GetBlobs() -> System.Collections.Generic.IEnumerable! +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.PersistentBlobProvider() -> void +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool \ No newline at end of file diff --git a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net6.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net6.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net6.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net6.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..5fa88c4d7b --- /dev/null +++ b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -0,0 +1,20 @@ +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryDelete() -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryLease(int leasePeriodMilliseconds) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryRead(out byte[]? buffer) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable! +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.PersistentBlob() -> void +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryDelete() -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryLease(int leasePeriodMilliseconds) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryRead(out byte[]? buffer) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.GetBlobs() -> System.Collections.Generic.IEnumerable! +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.PersistentBlobProvider() -> void +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool \ No newline at end of file diff --git a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/netstandard2.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/netstandard2.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..5fa88c4d7b --- /dev/null +++ b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -0,0 +1,20 @@ +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryDelete() -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryLease(int leasePeriodMilliseconds) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryRead(out byte[]? buffer) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable! +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.PersistentBlob() -> void +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryDelete() -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryLease(int leasePeriodMilliseconds) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryRead(out byte[]? buffer) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.GetBlobs() -> System.Collections.Generic.IEnumerable! +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.PersistentBlobProvider() -> void +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool \ No newline at end of file diff --git a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/AssemblyInfo.cs b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/AssemblyInfo.cs new file mode 100644 index 0000000000..fb9851b200 --- /dev/null +++ b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/AssemblyInfo.cs @@ -0,0 +1,19 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; + +[assembly: CLSCompliant(false)] diff --git a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/NotNullWhenAttribute.cs b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/NotNullWhenAttribute.cs new file mode 100644 index 0000000000..a84422c35b --- /dev/null +++ b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/NotNullWhenAttribute.cs @@ -0,0 +1,33 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#if NETSTANDARD2_0 || NET462 +namespace System.Diagnostics.CodeAnalysis +{ + [AttributeUsage(AttributeTargets.All)] + internal sealed class NotNullWhenAttribute : Attribute + { + /// Initializes a new instance of the class.Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this value, the associated parameter will not be null. + /// + public NotNullWhenAttribute(bool returnValue) => this.ReturnValue = returnValue; + + /// Gets a value indicating whether gets the return value condition. + public bool ReturnValue { get; } + } +} +#endif diff --git a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/OpenTelemetry.Extensions.PersistentStorage.Abstractions.csproj b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/OpenTelemetry.Extensions.PersistentStorage.Abstractions.csproj index 7590f91c89..7c663ea313 100644 --- a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/OpenTelemetry.Extensions.PersistentStorage.Abstractions.csproj +++ b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/OpenTelemetry.Extensions.PersistentStorage.Abstractions.csproj @@ -2,12 +2,16 @@ netstandard2.0;net462 + $(TargetFrameworks);net6.0 OpenTelemetry Persistent Storage Abstractions Extensions.PersistentStorage.Abstractions- $(NoWarn),1591 + enable + true + true diff --git a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/PersistentBlob.cs b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/PersistentBlob.cs index 82467df7cf..fd4f2d230c 100644 --- a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/PersistentBlob.cs +++ b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/PersistentBlob.cs @@ -15,6 +15,7 @@ // using System; +using System.Diagnostics.CodeAnalysis; namespace OpenTelemetry.Extensions.PersistentStorage.Abstractions { @@ -32,8 +33,9 @@ public abstract class PersistentBlob /// /// True if read was successful or else false. /// - public bool TryRead(out byte[] buffer) + public bool TryRead([NotNullWhen(true)] out byte[]? buffer) { +#pragma warning disable CA1031 // Do not catch general exception types try { return this.OnTryRead(out buffer); @@ -44,6 +46,7 @@ public bool TryRead(out byte[] buffer) buffer = null; return false; } +#pragma warning restore CA1031 // Do not catch general exception types } /// @@ -60,6 +63,7 @@ public bool TryRead(out byte[] buffer) /// public bool TryWrite(byte[] buffer, int leasePeriodMilliseconds = 0) { +#pragma warning disable CA1031 // Do not catch general exception types try { return this.OnTryWrite(buffer, leasePeriodMilliseconds); @@ -69,6 +73,7 @@ public bool TryWrite(byte[] buffer, int leasePeriodMilliseconds = 0) // TODO: log exception. return false; } +#pragma warning restore CA1031 // Do not catch general exception types } /// @@ -82,6 +87,7 @@ public bool TryWrite(byte[] buffer, int leasePeriodMilliseconds = 0) /// public bool TryLease(int leasePeriodMilliseconds) { +#pragma warning disable CA1031 // Do not catch general exception types try { return this.OnTryLease(leasePeriodMilliseconds); @@ -91,6 +97,7 @@ public bool TryLease(int leasePeriodMilliseconds) // TODO: log exception. return false; } +#pragma warning restore CA1031 // Do not catch general exception types } /// @@ -101,6 +108,7 @@ public bool TryLease(int leasePeriodMilliseconds) /// public bool TryDelete() { +#pragma warning disable CA1031 // Do not catch general exception types try { return this.OnTryDelete(); @@ -110,9 +118,10 @@ public bool TryDelete() // TODO: log exception. return false; } +#pragma warning restore CA1031 // Do not catch general exception types } - protected abstract bool OnTryRead(out byte[] buffer); + protected abstract bool OnTryRead([NotNullWhen(true)] out byte[]? buffer); protected abstract bool OnTryWrite(byte[] buffer, int leasePeriodMilliseconds = 0); diff --git a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/PersistentBlobProvider.cs b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/PersistentBlobProvider.cs index be35939d5b..431bf953e2 100644 --- a/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/PersistentBlobProvider.cs +++ b/src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/PersistentBlobProvider.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; namespace OpenTelemetry.Extensions.PersistentStorage.Abstractions @@ -40,8 +41,9 @@ public abstract class PersistentBlobProvider /// /// True if the blob was created or else false. /// - public bool TryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out PersistentBlob blob) + public bool TryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, [NotNullWhen(true)] out PersistentBlob? blob) { +#pragma warning disable CA1031 // Do not catch general exception types try { return this.OnTryCreateBlob(buffer, leasePeriodMilliseconds, out blob); @@ -52,6 +54,7 @@ public bool TryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out Persis blob = null; return false; } +#pragma warning restore CA1031 // Do not catch general exception types } /// @@ -66,8 +69,9 @@ public bool TryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out Persis /// /// True if the blob was created or else false. /// - public bool TryCreateBlob(byte[] buffer, out PersistentBlob blob) + public bool TryCreateBlob(byte[] buffer, [NotNullWhen(true)] out PersistentBlob? blob) { +#pragma warning disable CA1031 // Do not catch general exception types try { return this.OnTryCreateBlob(buffer, out blob); @@ -78,6 +82,7 @@ public bool TryCreateBlob(byte[] buffer, out PersistentBlob blob) blob = null; return false; } +#pragma warning restore CA1031 // Do not catch general exception types } /// @@ -89,8 +94,9 @@ public bool TryCreateBlob(byte[] buffer, out PersistentBlob blob) /// /// True if blob is present or else false. /// - public bool TryGetBlob(out PersistentBlob blob) + public bool TryGetBlob([NotNullWhen(true)] out PersistentBlob? blob) { +#pragma warning disable CA1031 // Do not catch general exception types try { return this.OnTryGetBlob(out blob); @@ -101,6 +107,7 @@ public bool TryGetBlob(out PersistentBlob blob) blob = null; return false; } +#pragma warning restore CA1031 // Do not catch general exception types } /// @@ -111,6 +118,7 @@ public bool TryGetBlob(out PersistentBlob blob) /// public IEnumerable GetBlobs() { +#pragma warning disable CA1031 // Do not catch general exception types try { return this.OnGetBlobs() ?? Enumerable.Empty(); @@ -120,14 +128,15 @@ public IEnumerable GetBlobs() // TODO: log exception return Enumerable.Empty(); } +#pragma warning restore CA1031 // Do not catch general exception types } protected abstract IEnumerable OnGetBlobs(); - protected abstract bool OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out PersistentBlob blob); + protected abstract bool OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, [NotNullWhen(true)] out PersistentBlob? blob); - protected abstract bool OnTryCreateBlob(byte[] buffer, out PersistentBlob blob); + protected abstract bool OnTryCreateBlob(byte[] buffer, [NotNullWhen(true)] out PersistentBlob? blob); - protected abstract bool OnTryGetBlob(out PersistentBlob blob); + protected abstract bool OnTryGetBlob([NotNullWhen(true)] out PersistentBlob? blob); } }