QuickImage – Rev 2

Subversion Repositories:
Rev:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using static System.Net.Mime.MediaTypeNames;

namespace Configuration
{
    [XmlRoot(ElementName = "DragDropConvertExclude")]
    public class DragDropConvertExclude : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private Images _images = new Images();

        [XmlElement(ElementName = "Image")]
        public Images Images
        {
            get => _images;
            set
            {
                if (Equals(value, _images))
                {
                    return;
                }

                _images = value;
                if (value is { Image: { } } && value.Image.Count != 0)
                {
                    excludedImages.UnionWith(value.Image);
                }
                OnPropertyChanged();
            }
        }

        private readonly HashSet<string> excludedImages = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
        
        public DragDropConvertExclude()
        {

        }

        public DragDropConvertExclude(string[] mimeTypes)
        {
            _images.Add(mimeTypes);
            excludedImages.UnionWith(mimeTypes);
        }

        public bool IsExcluded(string mime)
        {
            return excludedImages.Contains(mime);
        }

        public bool IsExcludedImage(string mime)
        {
            return excludedImages.Contains(mime);
        }

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(field, value)) return false;
            field = value;
            OnPropertyChanged(propertyName);
            return true;
        }
    }
}