diff --git a/src/Polly/Caching/AsyncCacheSyntax.cs b/src/Polly/Caching/AsyncCacheSyntax.cs
index d3c6ce6032b..2e5d4f24fa0 100644
--- a/src/Polly/Caching/AsyncCacheSyntax.cs
+++ b/src/Polly/Caching/AsyncCacheSyntax.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)
=> CacheAsync(cacheProvider, new RelativeTtl(ttl), DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);
///
@@ -28,7 +29,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, Tim
/// 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);
///
@@ -44,7 +45,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITt
/// 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);
///
@@ -61,7 +62,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, Tim
/// 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));
if (ttlStrategy == null) throw new ArgumentNullException(nameof(ttlStrategy));
@@ -86,7 +87,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITt
/// 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);
///
@@ -103,7 +104,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, Tim
/// 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));
if (ttlStrategy == null) throw new ArgumentNullException(nameof(ttlStrategy));
diff --git a/src/Polly/Caching/CacheSyntax.cs b/src/Polly/Caching/CacheSyntax.cs
index 8ab89c07118..abc7a537b15 100644
--- a/src/Polly/Caching/CacheSyntax.cs
+++ b/src/Polly/Caching/CacheSyntax.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 CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Action? onCacheError = null)
=> Cache(cacheProvider, new RelativeTtl(ttl), DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);
///
@@ -28,7 +29,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl,
/// The policy instance.
/// cacheProvider
/// ttlStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action? onCacheError = null)
=> Cache(cacheProvider, ttlStrategy, DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);
///
@@ -44,7 +45,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy t
/// The policy instance.
/// cacheProvider
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
=> Cache(cacheProvider, new RelativeTtl(ttl), cacheKeyStrategy.GetCacheKey, onCacheError);
///
@@ -61,7 +62,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl,
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
if (ttlStrategy == null) throw new ArgumentNullException(nameof(ttlStrategy));
@@ -86,7 +87,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy t
/// The policy instance.
/// cacheProvider
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Func cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Func cacheKeyStrategy, Action? onCacheError = null)
=> Cache(cacheProvider, new RelativeTtl(ttl), cacheKeyStrategy, onCacheError);
///
@@ -103,7 +104,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl,
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
if (ttlStrategy == null) throw new ArgumentNullException(nameof(ttlStrategy));
diff --git a/src/Polly/Caching/CacheTResultSyntax.cs b/src/Polly/Caching/CacheTResultSyntax.cs
index dbddd3b39d7..4b192a8529d 100644
--- a/src/Polly/Caching/CacheTResultSyntax.cs
+++ b/src/Polly/Caching/CacheTResultSyntax.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 CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -32,7 +33,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvid
/// The policy instance.
/// cacheProvider
/// ttlStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -52,7 +53,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvid
/// The policy instance.
/// cacheProvider
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -73,7 +74,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvid
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -93,7 +94,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvid
/// The policy instance.
/// cacheProvider
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Func cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Func cacheKeyStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -114,7 +115,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvid
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));
@@ -351,7 +352,7 @@ public static CachePolicy Cache(
/// 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 CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Action? onCacheError = null)
=> Cache(cacheProvider, new RelativeTtl(ttl), DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);
///
@@ -366,7 +367,7 @@ public static CachePolicy Cache(ISyncCacheProvider ca
/// The policy instance.
/// cacheProvider
/// ttlStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action? onCacheError = null)
=> Cache(cacheProvider, ttlStrategy, DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);
///
@@ -381,7 +382,7 @@ public static CachePolicy Cache(ISyncCacheProvider ca
/// The policy instance.
/// cacheProvider
/// ttlStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action? onCacheError = null)
=> Cache(cacheProvider, ttlStrategy, DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);
///
@@ -397,7 +398,7 @@ public static CachePolicy Cache(ISyncCacheProvider ca
/// The policy instance.
/// cacheProvider
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
=> Cache(cacheProvider, new RelativeTtl(ttl), cacheKeyStrategy.GetCacheKey, onCacheError);
///
@@ -414,7 +415,7 @@ public static CachePolicy Cache(ISyncCacheProvider ca
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
@@ -438,7 +439,7 @@ public static CachePolicy Cache(ISyncCacheProvider ca
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
@@ -461,7 +462,7 @@ public static CachePolicy Cache(ISyncCacheProvider ca
/// The policy instance.
/// cacheProvider
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Func cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, TimeSpan ttl, Func cacheKeyStrategy, Action? onCacheError = null)
=> Cache(cacheProvider, new RelativeTtl(ttl), cacheKeyStrategy, onCacheError);
///
@@ -478,7 +479,7 @@ public static CachePolicy Cache(ISyncCacheProvider ca
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
@@ -502,7 +503,7 @@ public static CachePolicy Cache(ISyncCacheProvider ca
/// cacheProvider
/// ttlStrategy
/// cacheKeyStrategy
- public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action onCacheError = null)
+ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
diff --git a/src/Polly/Retry/RetryEngine.cs b/src/Polly/Retry/RetryEngine.cs
index 1773d0890dd..527abe0972d 100644
--- a/src/Polly/Retry/RetryEngine.cs
+++ b/src/Polly/Retry/RetryEngine.cs
@@ -1,4 +1,5 @@
-namespace Polly.Retry;
+#nullable enable
+namespace Polly.Retry;
internal static class RetryEngine
{
@@ -10,11 +11,11 @@ internal static TResult Implementation(
ResultPredicates shouldRetryResultPredicates,
Action, TimeSpan, int, Context> onRetry,
int permittedRetryCount = Int32.MaxValue,
- IEnumerable sleepDurationsEnumerable = null,
- Func, Context, TimeSpan> sleepDurationProvider = null)
+ IEnumerable? sleepDurationsEnumerable = null,
+ Func, Context, TimeSpan>? sleepDurationProvider = null)
{
int tryCount = 0;
- IEnumerator sleepDurationsEnumerator = sleepDurationsEnumerable?.GetEnumerator();
+ IEnumerator? sleepDurationsEnumerator = sleepDurationsEnumerable?.GetEnumerator();
try
{
diff --git a/src/Polly/Retry/RetryPolicy.cs b/src/Polly/Retry/RetryPolicy.cs
index 8f043d18f65..e97b3535c7b 100644
--- a/src/Polly/Retry/RetryPolicy.cs
+++ b/src/Polly/Retry/RetryPolicy.cs
@@ -1,4 +1,5 @@
-namespace Polly.Retry;
+#nullable enable
+namespace Polly.Retry;
///
/// A retry policy that can be applied to synchronous delegates.
@@ -7,15 +8,15 @@ public class RetryPolicy : Policy, IRetryPolicy
{
private readonly Action _onRetry;
private readonly int _permittedRetryCount;
- private readonly IEnumerable _sleepDurationsEnumerable;
- private readonly Func _sleepDurationProvider;
+ private readonly IEnumerable? _sleepDurationsEnumerable;
+ private readonly Func? _sleepDurationProvider;
internal RetryPolicy(
PolicyBuilder policyBuilder,
Action onRetry,
int permittedRetryCount = Int32.MaxValue,
- IEnumerable sleepDurationsEnumerable = null,
- Func sleepDurationProvider = null
+ IEnumerable? sleepDurationsEnumerable = null,
+ Func? sleepDurationProvider = null
)
: base(policyBuilder)
{
@@ -38,7 +39,7 @@ protected override TResult Implementation(Func _sleepDurationProvider(retryCount, outcome.Exception, ctx)
- : (Func, Context, TimeSpan>)null
+ : (Func, Context, TimeSpan>?)null
);
}
@@ -49,15 +50,15 @@ public class RetryPolicy : Policy, IRetryPolicy
{
private readonly Action, TimeSpan, int, Context> _onRetry;
private readonly int _permittedRetryCount;
- private readonly IEnumerable _sleepDurationsEnumerable;
- private readonly Func, Context, TimeSpan> _sleepDurationProvider;
+ private readonly IEnumerable? _sleepDurationsEnumerable;
+ private readonly Func, Context, TimeSpan>? _sleepDurationProvider;
internal RetryPolicy(
PolicyBuilder policyBuilder,
Action, TimeSpan, int, Context> onRetry,
int permittedRetryCount = Int32.MaxValue,
- IEnumerable sleepDurationsEnumerable = null,
- Func, Context, TimeSpan> sleepDurationProvider = null
+ IEnumerable? sleepDurationsEnumerable = null,
+ Func, Context, TimeSpan>? sleepDurationProvider = null
)
: base(policyBuilder)
{