using System.Collections.Concurrent; using System.ComponentModel; using System.Runtime.CompilerServices; using Configuration.Annotations; namespace Configuration { public class Notifications : INotifyPropertyChanged { private readonly ConcurrentDictionary _notificationStates = new ConcurrentDictionary(); private NotificationState[] _notificationState = { new NotificationState { Type = NotificationType.SignalScanDetect, Enabled = false, LingerTime = 1000 } }; public Notifications() { if (_notificationStates.Count != 0) { return; } /* foreach (var state in _notificationState) { _notificationStates.TryAdd(state.Type, state); }*/ } public NotificationState[] State { get => _notificationState; set { if (value == _notificationState) return; _notificationState = value; foreach (var state in value) { _notificationStates.AddOrUpdate(state.Type, state, (k, v) => state); } OnPropertyChanged(); } } public event PropertyChangedEventHandler PropertyChanged; public bool TryGetNotificationState(NotificationType notificationType, out NotificationState notificationState) { return _notificationStates.TryGetValue(notificationType, out notificationState); } [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }