using System; namespace ComPDFKit.Tool.UndoManger { public class ReferenceObject { public class ReferenceChange { public T oldValue { get; set; } public T newValue { get; set; } } private static event EventHandler> Changed; public T Data { get;private set; } public ReferenceObject() { Changed += ReferenceObject_Changed; } ~ReferenceObject() { Changed -= ReferenceObject_Changed; } private void ReferenceObject_Changed(object sender, ReferenceChange newData) { if(Data==null && newData.oldValue==null) { Data = newData.newValue; return; } if (Data.Equals(newData.oldValue)) { Data = newData.newValue; } } public void Initialize(T newData) { Data = newData; } public void Update(T newData) { ReferenceChange changeData = new ReferenceChange() { oldValue = Data, newValue = newData }; Changed?.Invoke(this, changeData); } } }