using Biesse.PlantConfigurator.Core.Exceptions; using System; using System.Collections.ObjectModel; using System.Runtime.Serialization; namespace Biesse.PlantConfigurator.Core.SxData.SxParameterEdit { [Serializable] public class CustomObservableCollection : ObservableCollection { public CustomObservableCollection() { } [NonSerialized] public Func _isReadOnly; public Func IsReadOnly { get => _isReadOnly; set => _isReadOnly = value; } private bool isReadOnly { get { if (IsReadOnly != null) return IsReadOnly(); return false; } } public new void Add(T item) { if (isReadOnly) throw new ReadOnlyElementException(); base.Add(item); } public new void Clear() { if (isReadOnly) throw new ReadOnlyElementException(); base.Clear(); } public new void Insert(int index, T item) { if (isReadOnly) throw new ReadOnlyElementException(); base.Insert(index, item); } public new void Move(int oldIndex, int newIndex) { if (isReadOnly) throw new ReadOnlyElementException(); base.Move(oldIndex, newIndex); } public new bool Remove(T item) { if (isReadOnly) throw new ReadOnlyElementException(); return base.Remove(item); } public new void RemoveAt(int index) { if (isReadOnly) throw new ReadOnlyElementException(); base.RemoveAt(index); } } }