<PackageReference Include="Azure.Core" Version="1.47.3" />

RequestContext

public class RequestContext
Options that can be used to control the behavior of a request sent by a client.
using Azure.Core; using Azure.Core.Pipeline; using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Threading; namespace Azure { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class RequestContext { private bool _frozen; [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0 })] private (int Status, bool IsError)[] _statusCodes; [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] private ResponseClassificationHandler[] _handlers; [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0 })] internal (int Status, bool IsError)[] StatusCodes { [return: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0 })] get { return _statusCodes; } } [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] internal ResponseClassificationHandler[] Handlers { [return: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] get { return _handlers; } } [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0, 1 })] [field: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0, 1 })] internal List<(HttpPipelinePosition Position, HttpPipelinePolicy Policy)> Policies { [return: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0, 1 })] get; [param: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0, 1 })] private set; } public ErrorOptions ErrorOptions { get; set; } public CancellationToken CancellationToken { get; set; } = CancellationToken.None; public static implicit operator RequestContext(ErrorOptions options) { return new RequestContext { ErrorOptions = options }; } public void AddPolicy(HttpPipelinePolicy policy, HttpPipelinePosition position) { if (Policies == null) { List<(HttpPipelinePosition, HttpPipelinePolicy)> list2 = Policies = new List<(HttpPipelinePosition, HttpPipelinePolicy)>(); } Policies.Add((position, policy)); } public unsafe void AddClassifier(int statusCode, bool isError) { Argument.AssertInRange(statusCode, 100, 599, "statusCode"); if (_frozen) throw new InvalidOperationException("Cannot modify classifiers after this type has been used in a method call."); int num = (_statusCodes != null) ? _statusCodes.Length : 0; Array.Resize(ref *((int, bool)[]*)(&_statusCodes), num + 1); Array.Copy(_statusCodes, 0, _statusCodes, 1, num); _statusCodes[0] = (statusCode, isError); } public void AddClassifier(ResponseClassificationHandler classifier) { if (_frozen) throw new InvalidOperationException("Cannot modify classifiers after this type has been used in a method call."); int num = (_handlers != null) ? _handlers.Length : 0; Array.Resize(ref _handlers, num + 1); Array.Copy(_handlers, 0, _handlers, 1, num); _handlers[0] = classifier; } internal void Freeze() { _frozen = true; } internal ResponseClassifier Apply(ResponseClassifier classifier) { if (_statusCodes == null && _handlers == null) return classifier; StatusCodeClassifier statusCodeClassifier = classifier as StatusCodeClassifier; if (statusCodeClassifier != null) { StatusCodeClassifier statusCodeClassifier2 = statusCodeClassifier.Clone(); statusCodeClassifier2.Handlers = _handlers; if (_statusCodes != null) { (int, bool)[] statusCodes = _statusCodes; foreach ((int, bool) valueTuple in statusCodes) { statusCodeClassifier2.AddClassifier(valueTuple.Item1, valueTuple.Item2); } } return statusCodeClassifier2; } return new ChainingClassifier(_statusCodes, _handlers, classifier); } } }