Skip to content

Commit fae7486

Browse files
authored
Fix IDE1006 warning (#2112)
1 parent 261129b commit fae7486

20 files changed

+149
-143
lines changed

src/Polly/Caching/ContextualTtl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ContextualTtl : ITtlStrategy
1717
/// </summary>
1818
public static readonly string SlidingExpirationKey = "ContextualTtlSliding";
1919

20-
private static readonly Ttl _noTtl = new(TimeSpan.Zero, false);
20+
private static readonly Ttl NoTtl = new(TimeSpan.Zero, false);
2121

2222
/// <summary>
2323
/// Gets the TimeSpan for which to keep an item about to be cached, which may be influenced by data in the execution context.
@@ -29,7 +29,7 @@ public Ttl GetTtl(Context context, object? result)
2929
{
3030
if (!context.ContainsKey(TimeSpanKey))
3131
{
32-
return _noTtl;
32+
return NoTtl;
3333
}
3434

3535
bool sliding = false;

src/Polly/Caching/NonSlidingTtl.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ namespace Polly.Caching;
66
/// </summary>
77
public abstract class NonSlidingTtl : ITtlStrategy
88
{
9+
#pragma warning disable IDE1006
910
/// <summary>
1011
/// The absolute expiration time for cache items, represented by this strategy.
1112
/// </summary>
1213
protected readonly DateTimeOffset absoluteExpirationTime;
14+
#pragma warning restore IDE1006
1315

1416
/// <summary>
1517
/// Initializes a new instance of the <see cref="NonSlidingTtl"/> class.

src/Polly/Caching/RelativeTtl.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Polly.Caching;
66
/// </summary>
77
public class RelativeTtl : ITtlStrategy
88
{
9-
private readonly TimeSpan ttl;
9+
private readonly TimeSpan _ttl;
1010

1111
/// <summary>
1212
/// Initializes a new instance of the <see cref="RelativeTtl"/> class.
@@ -19,7 +19,7 @@ public RelativeTtl(TimeSpan ttl)
1919
throw new ArgumentOutOfRangeException(nameof(ttl), "The ttl for items to cache must be greater than zero.");
2020
}
2121

22-
this.ttl = ttl;
22+
_ttl = ttl;
2323
}
2424

2525
/// <summary>
@@ -28,5 +28,5 @@ public RelativeTtl(TimeSpan ttl)
2828
/// <param name="context">The execution context.</param>
2929
/// <param name="result">The execution result.</param>
3030
/// <returns>A <see cref="Ttl"/> representing the remaining Ttl of the cached item.</returns>
31-
public Ttl GetTtl(Context context, object? result) => new(ttl);
31+
public Ttl GetTtl(Context context, object? result) => new(_ttl);
3232
}

src/Polly/Caching/SlidingTtl.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Polly.Caching;
66
/// </summary>
77
public class SlidingTtl : ITtlStrategy
88
{
9-
private readonly Ttl ttl;
9+
private readonly Ttl _ttl;
1010

1111
/// <summary>
1212
/// Initializes a new instance of the <see cref="SlidingTtl"/> class.
@@ -19,7 +19,7 @@ public SlidingTtl(TimeSpan slidingTtl)
1919
throw new ArgumentOutOfRangeException(nameof(slidingTtl), "The ttl for items to cache must be greater than zero.");
2020
}
2121

22-
ttl = new Ttl(slidingTtl, true);
22+
_ttl = new Ttl(slidingTtl, true);
2323
}
2424

2525
/// <summary>
@@ -29,5 +29,5 @@ public SlidingTtl(TimeSpan slidingTtl)
2929
/// <param name="result">The execution result.</param>
3030
/// <returns>A <see cref="Ttl"/> representing the remaining Ttl of the cached item.</returns>
3131
public Ttl GetTtl(Context context, object? result) =>
32-
ttl;
32+
_ttl;
3333
}

src/Polly/CircuitBreaker/AdvancedCircuitController.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public AdvancedCircuitController(
2929

3030
public override void OnCircuitReset(Context context)
3131
{
32-
using var _ = TimedLock.Lock(_lock);
32+
using var _ = TimedLock.Lock(Lock);
3333

3434
// Is only null during initialization of the current class
3535
// as the variable is not set, before the base class calls
@@ -41,9 +41,9 @@ public override void OnCircuitReset(Context context)
4141

4242
public override void OnActionSuccess(Context context)
4343
{
44-
using var _ = TimedLock.Lock(_lock);
44+
using var _ = TimedLock.Lock(Lock);
4545

46-
switch (_circuitState)
46+
switch (InternalCircuitState)
4747
{
4848
case CircuitState.HalfOpen:
4949
OnCircuitReset(context);
@@ -65,11 +65,11 @@ public override void OnActionSuccess(Context context)
6565

6666
public override void OnActionFailure(DelegateResult<TResult> outcome, Context context)
6767
{
68-
using var _ = TimedLock.Lock(_lock);
68+
using var _ = TimedLock.Lock(Lock);
6969

70-
_lastOutcome = outcome;
70+
LastOutcome = outcome;
7171

72-
switch (_circuitState)
72+
switch (InternalCircuitState)
7373
{
7474
case CircuitState.HalfOpen:
7575
Break_NeedsLock(context);

src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@
55
/// </summary>
66
public class AsyncCircuitBreakerPolicy : AsyncPolicy, ICircuitBreakerPolicy
77
{
8-
internal readonly ICircuitController<EmptyStruct> _breakerController;
8+
internal readonly ICircuitController<EmptyStruct> BreakerController;
99

1010
internal AsyncCircuitBreakerPolicy(
1111
PolicyBuilder policyBuilder,
1212
ICircuitController<EmptyStruct> breakerController)
1313
: base(policyBuilder) =>
14-
_breakerController = breakerController;
14+
BreakerController = breakerController;
1515

1616
/// <summary>
1717
/// Gets the state of the underlying circuit.
1818
/// </summary>
19-
public CircuitState CircuitState => _breakerController.CircuitState;
19+
public CircuitState CircuitState => BreakerController.CircuitState;
2020

2121
/// <summary>
2222
/// Gets the last exception handled by the circuit-breaker.
2323
/// <remarks>This will be null if no exceptions have been handled by the circuit-breaker since the circuit last closed.</remarks>
2424
/// </summary>
25-
public Exception LastException => _breakerController.LastException;
25+
public Exception LastException => BreakerController.LastException;
2626

2727
/// <summary>
2828
/// Isolates (opens) the circuit manually, and holds it in this state until a call to <see cref="Reset()"/> is made.
2929
/// </summary>
3030
public void Isolate() =>
31-
_breakerController.Isolate();
31+
BreakerController.Isolate();
3232

3333
/// <summary>
3434
/// Closes the circuit, and resets any statistics controlling automated circuit-breaking.
3535
/// </summary>
3636
public void Reset() =>
37-
_breakerController.Reset();
37+
BreakerController.Reset();
3838

3939
/// <inheritdoc/>
4040
protected override async Task<TResult> ImplementationAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken,
@@ -48,7 +48,7 @@ await AsyncCircuitBreakerEngine.ImplementationAsync<EmptyStruct>(
4848
continueOnCapturedContext,
4949
ExceptionPredicates,
5050
ResultPredicates<EmptyStruct>.None,
51-
_breakerController).ConfigureAwait(continueOnCapturedContext);
51+
BreakerController).ConfigureAwait(continueOnCapturedContext);
5252
return result;
5353
}
5454
}
@@ -59,42 +59,42 @@ await AsyncCircuitBreakerEngine.ImplementationAsync<EmptyStruct>(
5959
/// <typeparam name="TResult">The return type of delegates which may be executed through the policy.</typeparam>
6060
public class AsyncCircuitBreakerPolicy<TResult> : AsyncPolicy<TResult>, ICircuitBreakerPolicy<TResult>
6161
{
62-
internal readonly ICircuitController<TResult> _breakerController;
62+
internal readonly ICircuitController<TResult> BreakerController;
6363

6464
internal AsyncCircuitBreakerPolicy(
6565
PolicyBuilder<TResult> policyBuilder,
6666
ICircuitController<TResult> breakerController)
6767
: base(policyBuilder) =>
68-
_breakerController = breakerController;
68+
BreakerController = breakerController;
6969

7070
/// <summary>
7171
/// Gets the state of the underlying circuit.
7272
/// </summary>
73-
public CircuitState CircuitState => _breakerController.CircuitState;
73+
public CircuitState CircuitState => BreakerController.CircuitState;
7474

7575
/// <summary>
7676
/// Gets the last exception handled by the circuit-breaker.
7777
/// <remarks>This will be null if no exceptions have been handled by the circuit-breaker since the circuit last closed.</remarks>
7878
/// </summary>
79-
public Exception LastException => _breakerController.LastException;
79+
public Exception LastException => BreakerController.LastException;
8080

8181
/// <summary>
8282
/// Gets the last result returned from a user delegate which the circuit-breaker handled.
8383
/// <remarks>This will be default(<typeparamref name="TResult"/>) if no results have been handled by the circuit-breaker since the circuit last closed, or if the last event handled by the circuit was an exception.</remarks>
8484
/// </summary>
85-
public TResult LastHandledResult => _breakerController.LastHandledResult;
85+
public TResult LastHandledResult => BreakerController.LastHandledResult;
8686

8787
/// <summary>
8888
/// Isolates (opens) the circuit manually, and holds it in this state until a call to <see cref="Reset()"/> is made.
8989
/// </summary>
9090
public void Isolate() =>
91-
_breakerController.Isolate();
91+
BreakerController.Isolate();
9292

9393
/// <summary>
9494
/// Closes the circuit, and resets any statistics controlling automated circuit-breaking.
9595
/// </summary>
9696
public void Reset() =>
97-
_breakerController.Reset();
97+
BreakerController.Reset();
9898

9999
/// <inheritdoc/>
100100
[DebuggerStepThrough]
@@ -107,5 +107,5 @@ protected override Task<TResult> ImplementationAsync(Func<Context, CancellationT
107107
continueOnCapturedContext,
108108
ExceptionPredicates,
109109
ResultPredicates,
110-
_breakerController);
110+
BreakerController);
111111
}

src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@
55
/// </summary>
66
public class CircuitBreakerPolicy : Policy, ICircuitBreakerPolicy
77
{
8-
internal readonly ICircuitController<EmptyStruct> _breakerController;
8+
internal readonly ICircuitController<EmptyStruct> BreakerController;
99

1010
internal CircuitBreakerPolicy(
1111
PolicyBuilder policyBuilder,
1212
ICircuitController<EmptyStruct> breakerController)
1313
: base(policyBuilder) =>
14-
_breakerController = breakerController;
14+
BreakerController = breakerController;
1515

1616
/// <summary>
1717
/// Gets the state of the underlying circuit.
1818
/// </summary>
19-
public CircuitState CircuitState => _breakerController.CircuitState;
19+
public CircuitState CircuitState => BreakerController.CircuitState;
2020

2121
/// <summary>
2222
/// Gets the last exception handled by the circuit-breaker.
2323
/// <remarks>This will be null if no exceptions have been handled by the circuit-breaker since the circuit last closed.</remarks>
2424
/// </summary>
25-
public Exception LastException => _breakerController.LastException;
25+
public Exception LastException => BreakerController.LastException;
2626

2727
/// <summary>
2828
/// Isolates (opens) the circuit manually, and holds it in this state until a call to <see cref="Reset()"/> is made.
2929
/// </summary>
3030
public void Isolate() =>
31-
_breakerController.Isolate();
31+
BreakerController.Isolate();
3232

3333
/// <summary>
3434
/// Closes the circuit, and resets any statistics controlling automated circuit-breaking.
3535
/// </summary>
3636
public void Reset() =>
37-
_breakerController.Reset();
37+
BreakerController.Reset();
3838

3939
/// <inheritdoc/>
4040
[DebuggerStepThrough]
@@ -47,7 +47,7 @@ protected override TResult Implementation<TResult>(Func<Context, CancellationTok
4747
cancellationToken,
4848
ExceptionPredicates,
4949
ResultPredicates<EmptyStruct>.None,
50-
_breakerController);
50+
BreakerController);
5151
return result;
5252
}
5353
}
@@ -58,42 +58,42 @@ protected override TResult Implementation<TResult>(Func<Context, CancellationTok
5858
/// <typeparam name="TResult">The type of the result.</typeparam>
5959
public class CircuitBreakerPolicy<TResult> : Policy<TResult>, ICircuitBreakerPolicy<TResult>
6060
{
61-
internal readonly ICircuitController<TResult> _breakerController;
61+
internal readonly ICircuitController<TResult> BreakerController;
6262

6363
internal CircuitBreakerPolicy(
6464
PolicyBuilder<TResult> policyBuilder,
6565
ICircuitController<TResult> breakerController)
6666
: base(policyBuilder) =>
67-
_breakerController = breakerController;
67+
BreakerController = breakerController;
6868

6969
/// <summary>
7070
/// Gets the state of the underlying circuit.
7171
/// </summary>
72-
public CircuitState CircuitState => _breakerController.CircuitState;
72+
public CircuitState CircuitState => BreakerController.CircuitState;
7373

7474
/// <summary>
7575
/// Gets the last exception handled by the circuit-breaker.
7676
/// <remarks>This will be null if no exceptions have been handled by the circuit-breaker since the circuit last closed, or if the last event handled by the circuit was a handled <typeparamref name="TResult"/> value.</remarks>
7777
/// </summary>
78-
public Exception LastException => _breakerController.LastException;
78+
public Exception LastException => BreakerController.LastException;
7979

8080
/// <summary>
8181
/// Gets the last result returned from a user delegate which the circuit-breaker handled.
8282
/// <remarks>This will be default(<typeparamref name="TResult"/>) if no results have been handled by the circuit-breaker since the circuit last closed, or if the last event handled by the circuit was an exception.</remarks>
8383
/// </summary>
84-
public TResult LastHandledResult => _breakerController.LastHandledResult;
84+
public TResult LastHandledResult => BreakerController.LastHandledResult;
8585

8686
/// <summary>
8787
/// Isolates (opens) the circuit manually, and holds it in this state until a call to <see cref="Reset()"/> is made.
8888
/// </summary>
8989
public void Isolate() =>
90-
_breakerController.Isolate();
90+
BreakerController.Isolate();
9191

9292
/// <summary>
9393
/// Closes the circuit, and resets any statistics controlling automated circuit-breaking.
9494
/// </summary>
9595
public void Reset() =>
96-
_breakerController.Reset();
96+
BreakerController.Reset();
9797

9898
/// <inheritdoc/>
9999
[DebuggerStepThrough]
@@ -104,5 +104,5 @@ protected override TResult Implementation(Func<Context, CancellationToken, TResu
104104
cancellationToken,
105105
ExceptionPredicates,
106106
ResultPredicates,
107-
_breakerController);
107+
BreakerController);
108108
}

0 commit comments

Comments
 (0)