<PackageReference Include="Polly.Core" Version="8.5.0" />

ResilienceContext

public sealed class ResilienceContext
A context assigned to a single execution of ResiliencePipeline. It is created manually or automatically when the user calls the various extensions on top of ResiliencePipeline. After every execution the context should be discarded and returned to the pool.
using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading; namespace Polly { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public sealed class ResilienceContext { [System.Runtime.CompilerServices.NullableContext(0)] private static class UnknownResult { } [System.Runtime.CompilerServices.Nullable(2)] [field: System.Runtime.CompilerServices.Nullable(2)] public string OperationKey { [System.Runtime.CompilerServices.NullableContext(2)] get; [System.Runtime.CompilerServices.NullableContext(2)] internal set; } public CancellationToken CancellationToken { get; set; } internal bool IsSynchronous { get; set; } internal Type ResultType { get; set; } = typeof(UnknownResult); internal bool IsVoid => ResultType == typeof(VoidResult); public bool ContinueOnCapturedContext { get; set; } internal bool IsInitialized => ResultType != typeof(UnknownResult); public ResilienceProperties Properties { get; } = new ResilienceProperties(); internal ResilienceContext() { } internal void InitializeFrom(ResilienceContext context, CancellationToken cancellationToken) { OperationKey = context.OperationKey; ResultType = context.ResultType; IsSynchronous = context.IsSynchronous; CancellationToken = context.CancellationToken; ContinueOnCapturedContext = context.ContinueOnCapturedContext; CancellationToken = cancellationToken; Properties.AddOrReplaceProperties(context.Properties); } [ExcludeFromCodeCoverage] [Conditional("DEBUG")] internal void AssertInitialized() { } internal ResilienceContext Initialize<[System.Runtime.CompilerServices.Nullable(2)] TResult>(bool isSynchronous) { IsSynchronous = isSynchronous; ResultType = typeof(TResult); return this; } internal bool Reset() { OperationKey = null; IsSynchronous = false; ResultType = typeof(UnknownResult); ContinueOnCapturedContext = false; CancellationToken = default(CancellationToken); Properties.Options.Clear(); return true; } } }