public void Remove(BaseReciever newItems) { if (newItems == null) { //throw new Exception("Cannot remove null element."); return; } else if (this[newItems.ID] != null) { items.Remove(this[newItems.ID]); } }
public void Copy(BaseReciever sourceReciever) { Type sourceType = sourceReciever.GetType();//获得该类的Type Type thisType = this.GetType(); FieldInfo[] sourceProperties = sourceType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (FieldInfo fieldInfo in sourceProperties) { object fieldValue = fieldInfo.GetValue(sourceReciever); string name = fieldInfo.Name; FieldInfo sourceInfo = thisType.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (sourceInfo != null) { sourceInfo.SetValue(this, fieldValue); } } }
public void Add(BaseReciever newItems, bool overwrite = true) { if (newItems == null) { throw new Exception("Cannot add null element."); } else if (this[newItems.ID] != null) { if (overwrite) { this[newItems.ID] = newItems; } else { throw new Exception("Cannot add existed element."); } } else { ids.Add(newItems.ID); this.items.Add(newItems); } }