CK.WPF.Controls.ValueConverterGroup.OnConvertersCollectionChanged C# (CSharp) Method

OnConvertersCollectionChanged() private method

private OnConvertersCollectionChanged ( object sender, NotifyCollectionChangedEventArgs e ) : void
sender object
e System.Collections.Specialized.NotifyCollectionChangedEventArgs
return void
        void OnConvertersCollectionChanged( object sender, NotifyCollectionChangedEventArgs e )
        {
            // The 'Converters' collection has been modified, so validate that each value converter it now
            // contains is decorated with ValueConversionAttribute and then cache the attribute value.

            IList convertersToProcess = null;
            if( e.Action == NotifyCollectionChangedAction.Add ||
                e.Action == NotifyCollectionChangedAction.Replace )
            {
                convertersToProcess = e.NewItems;
            }
            else if( e.Action == NotifyCollectionChangedAction.Remove )
            {
                foreach( IValueConverter converter in e.OldItems )
                    this.cachedAttributes.Remove( converter );
            }
            else if( e.Action == NotifyCollectionChangedAction.Reset )
            {
                this.cachedAttributes.Clear();
                convertersToProcess = this.converters;
            }

            if( convertersToProcess != null && convertersToProcess.Count > 0 )
            {
                foreach( IValueConverter converter in convertersToProcess )
                {
                    object[] attributes = converter.GetType().GetCustomAttributes( typeof( ValueConversionAttribute ), false );

                    if( attributes.Length != 1 )
                        throw new InvalidOperationException( "All value converters added to a ValueConverterGroup must be decorated with the ValueConversionAttribute attribute exactly once." );

                    this.cachedAttributes.Add( converter, attributes[0] as ValueConversionAttribute );
                }
            }
        }