using System.Collections.Concurrent; using System.ComponentModel; using System.Runtime.CompilerServices; using Configuration.Annotations; namespace Configuration { public class Definitions : INotifyPropertyChanged { private static readonly ConcurrentDictionary _metersToBand = new ConcurrentDictionary(); private Band[] _bands = { new Band { Meters = 6, Min = 050000000, Max = 054000000 }, new Band { Meters = 10, Min = 028000000, Max = 029700000 }, new Band { Meters = 11, Min = 026965000, Max = 027405000 }, new Band { Meters = 12, Min = 024920000, Max = 024990000 }, new Band { Meters = 15, Min = 021000000, Max = 021450000 }, new Band { Meters = 17, Min = 018068000, Max = 018168000 }, new Band { Meters = 20, Min = 014000000, Max = 014350000 }, new Band { Meters = 30, Min = 010100000, Max = 010150000 }, new Band { Meters = 40, Min = 007000000, Max = 007300000 } }; public Definitions() { if (_metersToBand.Count == 0) foreach (var band in _bands) _metersToBand.TryAdd(band.Meters, band); } public Band[] Bands { get => _bands; set { if (value == _bands) return; _metersToBand.Clear(); foreach (var band in value) _metersToBand.TryAdd(band.Meters, band); _bands = value; OnPropertyChanged(); } } public event PropertyChangedEventHandler PropertyChanged; /// /// Retrieve the minimum and maximum frequency from meters. /// /// meters corresponding to a band /// the band /// true upon a band definition existing public bool TryGetBand(int meters, out Band band) { return _metersToBand.TryGetValue(meters, out band); } [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }