DelegatingComponent
A component that delegates the execution to the next component in the chain.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Polly.Utils.Pipeline
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
internal sealed class DelegatingComponent : PipelineComponent
{
[System.Runtime.CompilerServices.Nullable(0)]
private readonly struct StateWrapper : IEquatable<StateWrapper>
{
public PipelineComponent Next { get; set; }
public object Callback { get; set; }
public object State { get; set; }
public StateWrapper(PipelineComponent Next, object Callback, object State)
{
Next = Next;
Callback = Callback;
State = State;
}
[System.Runtime.CompilerServices.NullableContext(0)]
[CompilerGenerated]
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("StateWrapper");
stringBuilder.Append(" { ");
if (PrintMembers(stringBuilder))
stringBuilder.Append(' ');
stringBuilder.Append('}');
return stringBuilder.ToString();
}
[System.Runtime.CompilerServices.NullableContext(0)]
[CompilerGenerated]
private bool PrintMembers(StringBuilder builder)
{
builder.Append("Next = ");
builder.Append(Next);
builder.Append(", Callback = ");
builder.Append(Callback);
builder.Append(", State = ");
builder.Append(State);
return true;
}
public static bool operator !=(StateWrapper left, StateWrapper right)
{
return !(left == right);
}
public static bool operator ==(StateWrapper left, StateWrapper right)
{
return left.Equals(right);
}
[CompilerGenerated]
public override int GetHashCode()
{
return (EqualityComparer<PipelineComponent>.Default.GetHashCode(Next) * -1521134295 + EqualityComparer<object>.Default.GetHashCode(Callback)) * -1521134295 + EqualityComparer<object>.Default.GetHashCode(State);
}
[System.Runtime.CompilerServices.NullableContext(0)]
[CompilerGenerated]
public override bool Equals(object obj)
{
if (obj is StateWrapper)
return Equals((StateWrapper)obj);
return false;
}
[CompilerGenerated]
public bool Equals(StateWrapper other)
{
if (EqualityComparer<PipelineComponent>.Default.Equals(Next, other.Next) && EqualityComparer<object>.Default.Equals(Callback, other.Callback))
return EqualityComparer<object>.Default.Equals(State, other.State);
return false;
}
[CompilerGenerated]
public void Deconstruct(out PipelineComponent Next, out object Callback, out object State)
{
Next = this.Next;
Callback = this.Callback;
State = this.State;
}
}
private readonly PipelineComponent _component;
[System.Runtime.CompilerServices.Nullable(2)]
[field: System.Runtime.CompilerServices.Nullable(2)]
public PipelineComponent Next {
[System.Runtime.CompilerServices.NullableContext(2)]
get;
[System.Runtime.CompilerServices.NullableContext(2)]
set;
}
public DelegatingComponent(PipelineComponent component)
{
_component = component;
}
public override ValueTask DisposeAsync()
{
return default(ValueTask);
}
[ExcludeFromCodeCoverage]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
0,
0,
1
})]
internal override ValueTask<Outcome<TResult>> ExecuteCore<[System.Runtime.CompilerServices.Nullable(2)] TResult, [System.Runtime.CompilerServices.Nullable(2)] TState>([System.Runtime.CompilerServices.Nullable(new byte[] {
1,
1,
1,
0,
0,
1
})] Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback, ResilienceContext context, TState state)
{
if (!RuntimeFeature.IsDynamicCodeSupported)
return ExecuteComponentAot(callback, context, state);
return ExecuteComponent(callback, context, state);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
0,
0,
1
})]
private static ValueTask<Outcome<TResult>> ExecuteNext<[System.Runtime.CompilerServices.Nullable(2)] TResult, [System.Runtime.CompilerServices.Nullable(2)] TState>(PipelineComponent next, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
1,
1,
0,
0,
1
})] Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback, ResilienceContext context, TState state)
{
if (context.CancellationToken.IsCancellationRequested)
return Outcome.FromExceptionAsValueTask<TResult>(new OperationCanceledException(context.CancellationToken).TrySetStackTrace());
return next.ExecuteCore(callback, context, state);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
0,
0,
1
})]
internal ValueTask<Outcome<TResult>> ExecuteComponent<[System.Runtime.CompilerServices.Nullable(2)] TResult, [System.Runtime.CompilerServices.Nullable(2)] TState>([System.Runtime.CompilerServices.Nullable(new byte[] {
1,
1,
1,
0,
0,
1
})] Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback, ResilienceContext context, TState state)
{
return _component.ExecuteCore((ResilienceContext context, (PipelineComponent Next, Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback, TState state) state) => DelegatingComponent.ExecuteNext<TResult, TState>(state.Next, state.callback, context, state.state), context, (Next, callback, state));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
0,
0,
1
})]
internal ValueTask<Outcome<TResult>> ExecuteComponentAot<[System.Runtime.CompilerServices.Nullable(2)] TResult, [System.Runtime.CompilerServices.Nullable(2)] TState>([System.Runtime.CompilerServices.Nullable(new byte[] {
1,
1,
1,
0,
0,
1
})] Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback, ResilienceContext context, TState state)
{
return _component.ExecuteCore(delegate(ResilienceContext context, StateWrapper wrapper) {
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback2 = (Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>>)wrapper.Callback;
TState state2 = (TState)wrapper.State;
return DelegatingComponent.ExecuteNext<TResult, TState>(wrapper.Next, callback2, context, state2);
}, context, new StateWrapper(Next, callback, state));
}
}
}