コード例 #1
0
        public static T As <T> (
            this Dictionary <DeskCharacteristicKey, ICharacteristicBase> dictionary,
            DeskCharacteristicKey key)
        {
            if (dictionary.TryGetValue(key,
                                       out var characteristicBase))
            {
                return(( T )characteristicBase);
            }

            if (UnknownBases.TryGetValue(key,
                                         out characteristicBase))
            {
                return(( T )characteristicBase);
            }

            throw new ArgumentException("",
                                        nameof(key));
        }
コード例 #2
0
        public IDeskCharacteristics WithCharacteristics(
            DeskCharacteristicKey key,
            [NotNull] ICharacteristicBase characteristic)
        {
            Guard.ArgumentNotNull(characteristic,
                                  nameof(characteristic));

            characteristic.Initialize <ICharacteristicBase> ( );

            if (_available.TryGetValue(key,
                                       out var oldCharacteristic))
            {
                oldCharacteristic.Dispose( );
            }

            _available [key] = characteristic;

            _logger.Debug($"Added characteristic {characteristic} for key {key}");

            return(this);
        }