ClientPipelineOptions
Options that control the creation of a  ClientPipeline used
            by a service client to send and receive HTTP messages.
            Service clients must create a client-specific subtype of this class
            to pass to their constructors to allow for service-specific options
            with a client-wide scope.
            
                using System.ClientModel.Internal;
using System.Runtime.CompilerServices;
namespace System.ClientModel.Primitives
{
    [System.Runtime.CompilerServices.NullableContext(2)]
    [System.Runtime.CompilerServices.Nullable(0)]
    public class ClientPipelineOptions
    {
        [System.Runtime.CompilerServices.Nullable(1)]
        private static readonly ClientPipelineOptions _defaultOptions = new ClientPipelineOptions();
        private bool _frozen;
        private PipelinePolicy _retryPolicy;
        private PipelinePolicy _loggingPolicy;
        private PipelineTransport _transport;
        private TimeSpan? _timeout;
        private ClientLoggingOptions _loggingOptions;
        private bool? _enabledDistributedTracing;
        [System.Runtime.CompilerServices.Nullable(1)]
        internal static ClientPipelineOptions Default {
            [System.Runtime.CompilerServices.NullableContext(1)]
            get {
                return _defaultOptions;
            }
        }
        public PipelinePolicy RetryPolicy {
            get {
                return _retryPolicy;
            }
            set {
                AssertNotFrozen();
                _retryPolicy = value;
            }
        }
        public PipelinePolicy MessageLoggingPolicy {
            get {
                return _loggingPolicy;
            }
            set {
                AssertNotFrozen();
                _loggingPolicy = value;
            }
        }
        public PipelineTransport Transport {
            get {
                return _transport;
            }
            set {
                AssertNotFrozen();
                _transport = value;
            }
        }
        public TimeSpan? NetworkTimeout {
            get {
                return _timeout;
            }
            set {
                AssertNotFrozen();
                _timeout = value;
            }
        }
        public ClientLoggingOptions ClientLoggingOptions {
            get {
                return _loggingOptions;
            }
            set {
                AssertNotFrozen();
                _loggingOptions = value;
            }
        }
        public bool? EnableDistributedTracing {
            get {
                return _enabledDistributedTracing;
            }
            set {
                AssertNotFrozen();
                _enabledDistributedTracing = value;
            }
        }
        [System.Runtime.CompilerServices.Nullable(new byte[] {
            2,
            1
        })]
        [field: System.Runtime.CompilerServices.Nullable(new byte[] {
            2,
            1
        })]
        internal PipelinePolicy[] PerCallPolicies {
            [return: System.Runtime.CompilerServices.Nullable(new byte[] {
                2,
                1
            })]
            get;
            [param: System.Runtime.CompilerServices.Nullable(new byte[] {
                2,
                1
            })]
            set;
        }
        [System.Runtime.CompilerServices.Nullable(new byte[] {
            2,
            1
        })]
        [field: System.Runtime.CompilerServices.Nullable(new byte[] {
            2,
            1
        })]
        internal PipelinePolicy[] PerTryPolicies {
            [return: System.Runtime.CompilerServices.Nullable(new byte[] {
                2,
                1
            })]
            get;
            [param: System.Runtime.CompilerServices.Nullable(new byte[] {
                2,
                1
            })]
            set;
        }
        [System.Runtime.CompilerServices.Nullable(new byte[] {
            2,
            1
        })]
        [field: System.Runtime.CompilerServices.Nullable(new byte[] {
            2,
            1
        })]
        internal PipelinePolicy[] BeforeTransportPolicies {
            [return: System.Runtime.CompilerServices.Nullable(new byte[] {
                2,
                1
            })]
            get;
            [param: System.Runtime.CompilerServices.Nullable(new byte[] {
                2,
                1
            })]
            set;
        }
        internal bool AddMessageLoggingPolicy => _loggingOptions?.AddMessageLoggingPolicy ?? true;
        [System.Runtime.CompilerServices.NullableContext(1)]
        public void AddPolicy(PipelinePolicy policy, PipelinePosition position)
        {
            Argument.AssertNotNull(policy, "policy");
            AssertNotFrozen();
            switch (position) {
            case PipelinePosition.PerCall:
                PerCallPolicies = AddPolicy(policy, PerCallPolicies);
                break;
            case PipelinePosition.PerTry:
                PerTryPolicies = AddPolicy(policy, PerTryPolicies);
                break;
            case PipelinePosition.BeforeTransport:
                BeforeTransportPolicies = AddPolicy(policy, BeforeTransportPolicies);
                break;
            default:
                throw new ArgumentException($"""{position}""");
            }
        }
        [System.Runtime.CompilerServices.NullableContext(1)]
        internal static PipelinePolicy[] AddPolicy(PipelinePolicy policy, [System.Runtime.CompilerServices.Nullable(new byte[] {
            2,
            1
        })] PipelinePolicy[] policies)
        {
            if (policies == null)
                policies = new PipelinePolicy[1];
            else {
                PipelinePolicy[] array = new PipelinePolicy[policies.Length + 1];
                policies.CopyTo(array.AsSpan());
                policies = array;
            }
            policies[policies.Length - 1] = policy;
            return policies;
        }
        public virtual void Freeze()
        {
            _frozen = true;
            _loggingOptions?.Freeze();
        }
        protected void AssertNotFrozen()
        {
            if (_frozen)
                throw new InvalidOperationException("Cannot change a ClientPipelineOptions instance after it has been used to create a ClientPipeline.");
        }
        [System.Runtime.CompilerServices.NullableContext(1)]
        internal HttpClientPipelineTransport GetHttpClientPipelineTransport()
        {
            if (_loggingOptions == null || _loggingOptions.UseDefaultClientWideLogging)
                return HttpClientPipelineTransport.Shared;
            return new HttpClientPipelineTransport(null, _loggingOptions.EnableLogging.GetValueOrDefault(true), _loggingOptions.LoggerFactory);
        }
        [System.Runtime.CompilerServices.NullableContext(1)]
        internal ClientRetryPolicy GetClientRetryPolicy()
        {
            if (_loggingOptions == null || _loggingOptions.UseDefaultClientWideLogging)
                return ClientRetryPolicy.Default;
            return new ClientRetryPolicy(3, _loggingOptions.EnableLogging.GetValueOrDefault(true), _loggingOptions.LoggerFactory);
        }
        [System.Runtime.CompilerServices.NullableContext(1)]
        internal MessageLoggingPolicy GetMessageLoggingPolicy()
        {
            if (_loggingOptions == null || _loggingOptions.AddDefaultMessageLoggingPolicy)
                return System.ClientModel.Primitives.MessageLoggingPolicy.Default;
            return new MessageLoggingPolicy(_loggingOptions);
        }
    }
}