public override bool Equals(object obj) { if (obj == null) { return(false); } CommonList <T> l = (CommonList <T>)obj; // Check size first if (_list.Count != l.Count) { return(false); } // Check values for (int i = 0; i < _list.Count; i++) { T item1 = (T)_list[i]; T item2 = (T)l[i]; if ((item2 == null) || !item1.Equals(item2)) { return(false); } } // No differences found return(true); }
public void MergeWith(object obj) { if (!MergeHelper.IsMergeable(this, obj)) { return; } CommonList <T> l = (CommonList <T>)obj; foreach (T item1 in l.List) { bool f = false; foreach (T item2 in _list) { if (item1.Equals(item2)) { if (typeof(IMergeable).IsAssignableFrom(item1.GetType())) { ((IMergeable)item1).MergeWith(item2); } f = true; break; } } if (!f) { Add(item1); } } }