/// <summary> /// Вызов деструктора, если объекты не равны /// </summary> /// <param name="obj1">Оригинальный объект</param> /// <param name="obj2">Объект для сравнения</param> public static void DisposeIfNotEqualTo(this IDisposable obj1, IDisposable obj2) { if (!(obj1 == null || obj1.Equals(obj2))) { obj1.Dispose(); } }
public void AddInstanceForDisposal(IDisposable instance) { if (instance == null || instance.Equals(_caller)) { return; } lock (_synchRoot) _items.Add(instance); }
/// <summary> 减少引用 /// </summary> /// <param name="token">通过Add方法获取的标记对象</param> public void Remove(IDisposable token) { if (token == null) { return; } if (token is CounterToken == false) { throw new ArgumentException("参数不是一个有效的引用标记", "token"); } if (token.Equals(this) == false) { throw new ArgumentOutOfRangeException("token", "此标记不属于当前计数器"); } token.Dispose(); }
public override bool Equals(object obj) { return(Object.Equals(obj)); }
private void ShowPanel(IDisposable panel) { pMultiAdd.Visible = panel.Equals(pMultiAdd); pMultiColor.Visible = panel.Equals(pMultiColor); pChannels.Visible = panel.Equals(pChannels); }