QuickImage – Rev 1

Subversion Repositories:
Rev:
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Xml.Serialization;

namespace Configuration
{
    [XmlRoot(Namespace = "urn:quickimage-configuration-schema", ElementName = "Configuration")]
    public class Configuration : INotifyPropertyChanged
    {
        private SupportedFormats _supportedFormats = new SupportedFormats();
        private OutboundDragDrop _outboundDragDrop = new OutboundDragDrop();
        private InboundDragDrop _inboundDragDrop = new InboundDragDrop();

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

                _supportedFormats = value;
                OnPropertyChanged();
            }
        }

        public OutboundDragDrop OutboundDragDrop
        {
            get => _outboundDragDrop;
            set
            {
                if (Equals(value, _outboundDragDrop)) return;
                _outboundDragDrop = value;
                OnPropertyChanged();
            }
        }

        public InboundDragDrop InboundDragDrop
        {
            get => _inboundDragDrop;
            set
            {
                if (Equals(value, _inboundDragDrop)) return;
                _inboundDragDrop = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        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;
        }
    }
}