using System.ComponentModel; using System.Runtime.CompilerServices; using System.Xml.Serialization; using TrackedFolders.Properties; using TrackedFolders.Utilities; namespace TrackedFolders { [XmlRoot(Namespace = "urn:horizon-tracked-folders-schema", ElementName = "TrackedFolders")] public class TrackedFolders : INotifyPropertyChanged { #region Private Delegates, Events, Enums, Properties, Indexers and Fields private BindingListWithCollectionChanged _folder = new BindingListWithCollectionChanged(); #endregion #region Constructors [UsedImplicitly] public TrackedFolders() { } #endregion #region Public Enums, Properties and Fields public BindingListWithCollectionChanged Folder { get => _folder; set { if (Equals(value, _folder)) { return; } _folder = value; OnPropertyChanged(); } } #endregion #region Interface public event PropertyChangedEventHandler PropertyChanged; #endregion #region Private Methods [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } #endregion #region Public Methods public bool TryGet(string path, out Folder folder) { foreach (var tracked in Folder) { if (!path.IsPathEqual(tracked.Path) && !path.IsSubPathOf(tracked.Path)) { continue; } folder = tracked; return true; } folder = null; return false; } #endregion } }