PipelineMessage
Represents an HTTP message that can be sent from a
             ClientPipeline.   Request holds the request sent
            to the cloud service, and  Response holds the response received
            from the service.
            
                using System.ClientModel.Internal;
using System.Runtime.CompilerServices;
using System.Threading;
namespace System.ClientModel.Primitives
{
    [System.Runtime.CompilerServices.NullableContext(1)]
    [System.Runtime.CompilerServices.Nullable(0)]
    public class PipelineMessage : IDisposable
    {
        [System.Runtime.CompilerServices.Nullable(new byte[] {
            0,
            1
        })]
        private ArrayBackedPropertyBag<ulong, object> _propertyBag;
        private bool _disposed;
        public PipelineRequest Request { get; }
        [System.Runtime.CompilerServices.Nullable(2)]
        [field: System.Runtime.CompilerServices.Nullable(2)]
        public PipelineResponse Response {
            [System.Runtime.CompilerServices.NullableContext(2)]
            get;
            [System.Runtime.CompilerServices.NullableContext(2)]
            protected internal set;
        }
        public CancellationToken CancellationToken { get; set; }
        public PipelineMessageClassifier ResponseClassifier { get; set; }
        internal int RetryCount { get; set; }
        public bool BufferResponse { get; set; }
        public TimeSpan? NetworkTimeout { get; set; }
        internal bool UseCustomRequestPipeline {
            get {
                if (PerCallPolicies == null && PerTryPolicies == null)
                    return BeforeTransportPolicies != null;
                return true;
            }
        }
        [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;
        }
        protected internal PipelineMessage(PipelineRequest request)
        {
            Argument.AssertNotNull(request, "request");
            Request = request;
            _propertyBag = new ArrayBackedPropertyBag<ulong, object>();
            BufferResponse = true;
            ResponseClassifier = PipelineMessageClassifier.Default;
        }
        [System.Runtime.CompilerServices.NullableContext(2)]
        public PipelineResponse ExtractResponse()
        {
            PipelineResponse response = Response;
            Response = null;
            return response;
        }
        internal void AssertResponse()
        {
            if (Response == null)
                throw new InvalidOperationException("'Response' property is not set on message.");
        }
        [System.Runtime.CompilerServices.NullableContext(2)]
        public void Apply(RequestOptions options)
        {
            options?.Apply(this);
        }
        public bool TryGetProperty(Type key, [System.Runtime.CompilerServices.Nullable(2)] out object value)
        {
            return _propertyBag.TryGetValue((ulong)(long)key.TypeHandle.Value, out value);
        }
        public void SetProperty(Type key, [System.Runtime.CompilerServices.Nullable(2)] object value)
        {
            _propertyBag.Set((ulong)(long)key.TypeHandle.Value, value);
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        protected virtual void Dispose(bool disposing)
        {
            if (disposing && !_disposed) {
                Response?.Dispose();
                Response = null;
                Request?.Dispose();
                _propertyBag.Dispose();
                _disposed = true;
            }
        }
    }
}