void IFeatureCollection.Set <TFeature>(TFeature?feature) where TFeature : default
        {
            // Using Unsafe.As for the cast due to https://github.com/dotnet/runtime/issues/49614
            // The type of TFeature is confirmed by the typeof() check and the As cast only accepts
            // that type; however the Jit does not eliminate a regular cast in a shared generic.

            _featureRevision++;
            if (typeof(TFeature) == typeof(IConnectionIdFeature))
            {
                _currentIConnectionIdFeature = Unsafe.As <TFeature?, IConnectionIdFeature?>(ref feature);
            }
            else if (typeof(TFeature) == typeof(IConnectionTransportFeature))
            {
                _currentIConnectionTransportFeature = Unsafe.As <TFeature?, IConnectionTransportFeature?>(ref feature);
            }
            else if (typeof(TFeature) == typeof(IConnectionItemsFeature))
            {
                _currentIConnectionItemsFeature = Unsafe.As <TFeature?, IConnectionItemsFeature?>(ref feature);
            }
            else if (typeof(TFeature) == typeof(IPersistentStateFeature))
            {
                _currentIPersistentStateFeature = Unsafe.As <TFeature?, IPersistentStateFeature?>(ref feature);
            }
            else if (typeof(TFeature) == typeof(IMemoryPoolFeature))
            {
                _currentIMemoryPoolFeature = Unsafe.As <TFeature?, IMemoryPoolFeature?>(ref feature);
            }
            else if (typeof(TFeature) == typeof(IConnectionLifetimeFeature))
            {
                _currentIConnectionLifetimeFeature = Unsafe.As <TFeature?, IConnectionLifetimeFeature?>(ref feature);
            }
            else if (typeof(TFeature) == typeof(IConnectionSocketFeature))
            {
                _currentIConnectionSocketFeature = Unsafe.As <TFeature?, IConnectionSocketFeature?>(ref feature);
            }
            else if (typeof(TFeature) == typeof(IProtocolErrorCodeFeature))
            {
                _currentIProtocolErrorCodeFeature = Unsafe.As <TFeature?, IProtocolErrorCodeFeature?>(ref feature);
            }
            else if (typeof(TFeature) == typeof(IStreamDirectionFeature))
            {
                _currentIStreamDirectionFeature = Unsafe.As <TFeature?, IStreamDirectionFeature?>(ref feature);
            }
            else if (typeof(TFeature) == typeof(IStreamIdFeature))
            {
                _currentIStreamIdFeature = Unsafe.As <TFeature?, IStreamIdFeature?>(ref feature);
            }
            else if (typeof(TFeature) == typeof(IStreamAbortFeature))
            {
                _currentIStreamAbortFeature = Unsafe.As <TFeature?, IStreamAbortFeature?>(ref feature);
            }
            else if (typeof(TFeature) == typeof(IStreamClosedFeature))
            {
                _currentIStreamClosedFeature = Unsafe.As <TFeature?, IStreamClosedFeature?>(ref feature);
            }
            else
            {
                ExtraFeatureSet(typeof(TFeature), feature);
            }
        }
 private void FastReset()
 {
     _currentIConnectionIdFeature        = this;
     _currentIConnectionTransportFeature = this;
     _currentIConnectionItemsFeature     = this;
     _currentIMemoryPoolFeature          = this;
     _currentIConnectionLifetimeFeature  = this;
 }
Beispiel #3
0
        private void FastReset()
        {
            _currentIConnectionIdFeature       = this;
            _currentIConnectionItemsFeature    = this;
            _currentIMemoryPoolFeature         = this;
            _currentIConnectionLifetimeFeature = this;

            _currentIConnectionTransportFeature = null;
            _currentIProtocolErrorCodeFeature   = null;
            _currentITlsConnectionFeature       = null;
        }
Beispiel #4
0
        private void FastReset()
        {
            _currentIConnectionIdFeature        = this;
            _currentIConnectionTransportFeature = this;
            _currentIConnectionItemsFeature     = this;
            _currentIMemoryPoolFeature          = this;
            _currentIConnectionLifetimeFeature  = this;

            _currentIPersistentStateFeature   = null;
            _currentIConnectionSocketFeature  = null;
            _currentIProtocolErrorCodeFeature = null;
            _currentIStreamDirectionFeature   = null;
            _currentIStreamIdFeature          = null;
            _currentIStreamAbortFeature       = null;
        }
        object?IFeatureCollection.this[Type key]
        {
            get
            {
                object?feature = null;
                if (key == typeof(IConnectionIdFeature))
                {
                    feature = _currentIConnectionIdFeature;
                }
                else if (key == typeof(IConnectionTransportFeature))
                {
                    feature = _currentIConnectionTransportFeature;
                }
                else if (key == typeof(IConnectionItemsFeature))
                {
                    feature = _currentIConnectionItemsFeature;
                }
                else if (key == typeof(IPersistentStateFeature))
                {
                    feature = _currentIPersistentStateFeature;
                }
                else if (key == typeof(IMemoryPoolFeature))
                {
                    feature = _currentIMemoryPoolFeature;
                }
                else if (key == typeof(IConnectionLifetimeFeature))
                {
                    feature = _currentIConnectionLifetimeFeature;
                }
                else if (key == typeof(IConnectionSocketFeature))
                {
                    feature = _currentIConnectionSocketFeature;
                }
                else if (key == typeof(IProtocolErrorCodeFeature))
                {
                    feature = _currentIProtocolErrorCodeFeature;
                }
                else if (key == typeof(IStreamDirectionFeature))
                {
                    feature = _currentIStreamDirectionFeature;
                }
                else if (key == typeof(IStreamIdFeature))
                {
                    feature = _currentIStreamIdFeature;
                }
                else if (key == typeof(IStreamAbortFeature))
                {
                    feature = _currentIStreamAbortFeature;
                }
                else if (key == typeof(IStreamClosedFeature))
                {
                    feature = _currentIStreamClosedFeature;
                }
                else if (MaybeExtra != null)
                {
                    feature = ExtraFeatureGet(key);
                }

                return(feature ?? MultiplexedConnectionFeatures?[key]);
            }

            set
            {
                _featureRevision++;

                if (key == typeof(IConnectionIdFeature))
                {
                    _currentIConnectionIdFeature = (IConnectionIdFeature?)value;
                }
                else if (key == typeof(IConnectionTransportFeature))
                {
                    _currentIConnectionTransportFeature = (IConnectionTransportFeature?)value;
                }
                else if (key == typeof(IConnectionItemsFeature))
                {
                    _currentIConnectionItemsFeature = (IConnectionItemsFeature?)value;
                }
                else if (key == typeof(IPersistentStateFeature))
                {
                    _currentIPersistentStateFeature = (IPersistentStateFeature?)value;
                }
                else if (key == typeof(IMemoryPoolFeature))
                {
                    _currentIMemoryPoolFeature = (IMemoryPoolFeature?)value;
                }
                else if (key == typeof(IConnectionLifetimeFeature))
                {
                    _currentIConnectionLifetimeFeature = (IConnectionLifetimeFeature?)value;
                }
                else if (key == typeof(IConnectionSocketFeature))
                {
                    _currentIConnectionSocketFeature = (IConnectionSocketFeature?)value;
                }
                else if (key == typeof(IProtocolErrorCodeFeature))
                {
                    _currentIProtocolErrorCodeFeature = (IProtocolErrorCodeFeature?)value;
                }
                else if (key == typeof(IStreamDirectionFeature))
                {
                    _currentIStreamDirectionFeature = (IStreamDirectionFeature?)value;
                }
                else if (key == typeof(IStreamIdFeature))
                {
                    _currentIStreamIdFeature = (IStreamIdFeature?)value;
                }
                else if (key == typeof(IStreamAbortFeature))
                {
                    _currentIStreamAbortFeature = (IStreamAbortFeature?)value;
                }
                else if (key == typeof(IStreamClosedFeature))
                {
                    _currentIStreamClosedFeature = (IStreamClosedFeature?)value;
                }
                else
                {
                    ExtraFeatureSet(key, value);
                }
            }
        }
Beispiel #6
0
        object?IFeatureCollection.this[Type key]
        {
            get
            {
                object?feature = null;
                if (key == typeof(IConnectionIdFeature))
                {
                    feature = _currentIConnectionIdFeature;
                }
                else if (key == typeof(IConnectionTransportFeature))
                {
                    feature = _currentIConnectionTransportFeature;
                }
                else if (key == typeof(IConnectionItemsFeature))
                {
                    feature = _currentIConnectionItemsFeature;
                }
                else if (key == typeof(IMemoryPoolFeature))
                {
                    feature = _currentIMemoryPoolFeature;
                }
                else if (key == typeof(IConnectionLifetimeFeature))
                {
                    feature = _currentIConnectionLifetimeFeature;
                }
                else if (key == typeof(IProtocolErrorCodeFeature))
                {
                    feature = _currentIProtocolErrorCodeFeature;
                }
                else if (key == typeof(ITlsConnectionFeature))
                {
                    feature = _currentITlsConnectionFeature;
                }
                else if (MaybeExtra != null)
                {
                    feature = ExtraFeatureGet(key);
                }

                return(feature);
            }

            set
            {
                _featureRevision++;

                if (key == typeof(IConnectionIdFeature))
                {
                    _currentIConnectionIdFeature = (IConnectionIdFeature?)value;
                }
                else if (key == typeof(IConnectionTransportFeature))
                {
                    _currentIConnectionTransportFeature = (IConnectionTransportFeature?)value;
                }
                else if (key == typeof(IConnectionItemsFeature))
                {
                    _currentIConnectionItemsFeature = (IConnectionItemsFeature?)value;
                }
                else if (key == typeof(IMemoryPoolFeature))
                {
                    _currentIMemoryPoolFeature = (IMemoryPoolFeature?)value;
                }
                else if (key == typeof(IConnectionLifetimeFeature))
                {
                    _currentIConnectionLifetimeFeature = (IConnectionLifetimeFeature?)value;
                }
                else if (key == typeof(IProtocolErrorCodeFeature))
                {
                    _currentIProtocolErrorCodeFeature = (IProtocolErrorCodeFeature?)value;
                }
                else if (key == typeof(ITlsConnectionFeature))
                {
                    _currentITlsConnectionFeature = (ITlsConnectionFeature?)value;
                }
                else
                {
                    ExtraFeatureSet(key, value);
                }
            }
        }