diff --git a/src/Polly/AsyncPolicy.TResult.cs b/src/Polly/AsyncPolicy.TResult.cs
index b8dfbd4555a..e6c8898a168 100644
--- a/src/Polly/AsyncPolicy.TResult.cs
+++ b/src/Polly/AsyncPolicy.TResult.cs
@@ -1,4 +1,5 @@
-namespace Polly;
+#nullable enable
+namespace Polly;
///
/// Transient exception handling policies that can be applied to asynchronous delegates
@@ -22,7 +23,7 @@ internal AsyncPolicy(
/// Constructs a new instance of a derived type with the passed .
///
/// A indicating which exceptions and results the policy should handle.
- protected AsyncPolicy(PolicyBuilder policyBuilder = null)
+ protected AsyncPolicy(PolicyBuilder? policyBuilder = null)
: base(policyBuilder)
{
}
diff --git a/src/Polly/AsyncPolicy.cs b/src/Polly/AsyncPolicy.cs
index 50d5b910ae3..e2a37c717c3 100644
--- a/src/Polly/AsyncPolicy.cs
+++ b/src/Polly/AsyncPolicy.cs
@@ -1,4 +1,5 @@
-namespace Polly;
+#nullable enable
+namespace Polly;
///
/// Transient exception handling policies that can be applied to asynchronous delegates
@@ -18,7 +19,7 @@ internal AsyncPolicy(ExceptionPredicates exceptionPredicates)
/// Constructs a new instance of a derived type with the passed .
///
/// A specifying which exceptions the policy should handle.
- protected AsyncPolicy(PolicyBuilder policyBuilder = null)
+ protected AsyncPolicy(PolicyBuilder? policyBuilder = null)
: base(policyBuilder)
{
}
diff --git a/src/Polly/Caching/AsyncCacheTResultSyntax.cs b/src/Polly/Caching/AsyncCacheTResultSyntax.cs
index 6faad6d8c7c..1f76748397d 100644
--- a/src/Polly/Caching/AsyncCacheTResultSyntax.cs
+++ b/src/Polly/Caching/AsyncCacheTResultSyntax.cs
@@ -1,4 +1,5 @@
-namespace Polly;
+#nullable enable
+namespace Polly;
public partial class Policy
{
@@ -13,7 +14,7 @@ public partial class Policy
/// Delegate to call if an exception is thrown when attempting to get a value from or put a value into the cache, passing the execution context, the cache key, and the exception.
/// The policy instance.
/// cacheProvider
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -32,7 +33,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider
/// The policy instance.
/// cacheProvider
/// ttlStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -52,7 +53,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider
/// The policy instance.
/// cacheProvider
/// cacheKeyStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -73,7 +74,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -93,7 +94,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider
/// The policy instance.
/// cacheProvider
/// cacheKeyStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Func cacheKeyStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Func cacheKeyStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -114,7 +115,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -351,7 +352,7 @@ public static AsyncCachePolicy CacheAsync(
/// Delegate to call if an exception is thrown when attempting to get a value from or put a value into the cache, passing the execution context, the cache key, and the exception.
/// The policy instance.
/// cacheProvider
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Action? onCacheError = null)
=> CacheAsync(cacheProvider, new RelativeTtl(ttl), DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);
///
@@ -366,7 +367,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider<
/// The policy instance.
/// cacheProvider
/// ttlStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action? onCacheError = null)
=> CacheAsync(cacheProvider, ttlStrategy, DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);
///
@@ -381,7 +382,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider<
/// The policy instance.
/// cacheProvider
/// ttlStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action? onCacheError = null)
=> CacheAsync(cacheProvider, ttlStrategy, DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);
///
@@ -397,7 +398,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider<
/// The policy instance.
/// cacheProvider
/// cacheKeyStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
=> CacheAsync(cacheProvider, new RelativeTtl(ttl), cacheKeyStrategy.GetCacheKey, onCacheError);
///
@@ -414,7 +415,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider<
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
@@ -437,7 +438,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider<
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
@@ -459,7 +460,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider<
/// The policy instance.
/// cacheProvider
/// cacheKeyStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Func cacheKeyStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Func cacheKeyStrategy, Action? onCacheError = null)
=> CacheAsync(cacheProvider, new RelativeTtl(ttl), cacheKeyStrategy, onCacheError);
///
@@ -476,7 +477,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider<
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
@@ -499,7 +500,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider<
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action onCacheError = null)
+ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
diff --git a/src/Polly/Policy.TResult.cs b/src/Polly/Policy.TResult.cs
index a6512eaafcd..8f52e3a1cc9 100644
--- a/src/Polly/Policy.TResult.cs
+++ b/src/Polly/Policy.TResult.cs
@@ -1,4 +1,5 @@
-namespace Polly;
+#nullable enable
+namespace Polly;
///
/// Transient fault handling policies that can be applied to delegates returning results of type
@@ -19,7 +20,7 @@ internal Policy(ExceptionPredicates exceptionPredicates, ResultPredicates type with the passed .
///
/// A indicating which exceptions and results the policy should handle.
- protected Policy(PolicyBuilder policyBuilder = null)
+ protected Policy(PolicyBuilder? policyBuilder = null)
: base(policyBuilder)
{
}
diff --git a/src/Polly/Policy.cs b/src/Polly/Policy.cs
index 448defb34c1..7d8a02ac1ba 100644
--- a/src/Polly/Policy.cs
+++ b/src/Polly/Policy.cs
@@ -1,4 +1,5 @@
-namespace Polly;
+#nullable enable
+namespace Polly;
///
/// Transient exception handling policies that can be applied to synchronous delegates
@@ -18,7 +19,7 @@ internal Policy(ExceptionPredicates exceptionPredicates)
/// Constructs a new instance of a derived type with the passed .
///
/// A specifying which exceptions the policy should handle.
- protected Policy(PolicyBuilder policyBuilder = null)
+ protected Policy(PolicyBuilder? policyBuilder = null)
: base(policyBuilder)
{
}
diff --git a/src/Polly/Retry/AsyncRetryEngine.cs b/src/Polly/Retry/AsyncRetryEngine.cs
index 8eb287e6e6f..57ae503de15 100644
--- a/src/Polly/Retry/AsyncRetryEngine.cs
+++ b/src/Polly/Retry/AsyncRetryEngine.cs
@@ -1,4 +1,5 @@
-namespace Polly.Retry;
+#nullable enable
+namespace Polly.Retry;
internal static class AsyncRetryEngine
{
@@ -10,12 +11,12 @@ internal static async Task ImplementationAsync(
ResultPredicates shouldRetryResultPredicates,
Func, TimeSpan, int, Context, Task> onRetryAsync,
int permittedRetryCount = Int32.MaxValue,
- IEnumerable sleepDurationsEnumerable = null,
- Func, Context, TimeSpan> sleepDurationProvider = null,
+ IEnumerable? sleepDurationsEnumerable = null,
+ Func, Context, TimeSpan>? sleepDurationProvider = null,
bool continueOnCapturedContext = false)
{
int tryCount = 0;
- IEnumerator sleepDurationsEnumerator = sleepDurationsEnumerable?.GetEnumerator();
+ IEnumerator? sleepDurationsEnumerator = sleepDurationsEnumerable?.GetEnumerator();
try
{