public void Add(SurfaceBoxRenderer addMe, bool alwaysOnTop) { SurfaceBoxRenderer[] startList = alwaysOnTop ? this._topList : this._list; var listPlusOne = new SurfaceBoxRenderer[startList.Length + 1]; for (int i = 0; i < startList.Length; ++i) { listPlusOne[i] = startList[i]; } listPlusOne[listPlusOne.Length - 1] = addMe; if (alwaysOnTop) { this._topList = listPlusOne; } else { this._list = listPlusOne; } Invalidate(); }
public void Remove(SurfaceBoxRenderer removeMe) { if (this._list.Length == 0 && this._topList.Length == 0) { throw new InvalidOperationException("zero items left, can't remove anything"); } else { bool found = false; if (this._list.Length > 0) { var listSubOne = new SurfaceBoxRenderer[this._list.Length - 1]; bool foundHere = false; int dstIndex = 0; for (int i = 0; i < this._list.Length; ++i) { if (this._list[i] == removeMe) { if (foundHere) { throw new ArgumentException("removeMe appeared multiple times in the list"); } else { foundHere = true; } } else { if (dstIndex == this._list.Length - 1) { // was not found } else { listSubOne[dstIndex] = this._list[i]; ++dstIndex; } } } if (foundHere) { this._list = listSubOne; found = true; } } if (this._topList.Length > 0) { var topListSubOne = new SurfaceBoxRenderer[this._topList.Length - 1]; int topDstIndex = 0; bool foundHere = false; for (int i = 0; i < this._topList.Length; ++i) { if (this._topList[i] == removeMe) { if (found || foundHere) { throw new ArgumentException("removeMe appeared multiple times in the list"); } else { foundHere = true; } } else { if (topDstIndex == this._topList.Length - 1) { // was not found } else { topListSubOne[topDstIndex] = this._topList[i]; ++topDstIndex; } } } if (foundHere) { this._topList = topListSubOne; found = true; } } if (!found) { throw new ArgumentException("removeMe was not found", "removeMe"); } Invalidate(); } }