/// <summary> /// Create a profile for a grid. /// </summary> /// <param name="grid">grid to profile</param> private GridShapeProfiler(IMyCubeGrid grid) { this.myCubeGrid = grid; myLogger = new Logger("GridShapeProfiler", () => myCubeGrid.DisplayName); this.SlimBlocks = new ListSnapshots <IMySlimBlock>(); // instead of iterating over blocks, test cells of grid for contents (no need to lock grid) ReadOnlyList <IMySlimBlock> mutable = SlimBlocks.mutable(); myCubeGrid.Min.ForEachVector(myCubeGrid.Max, (cell) => { IMySlimBlock slim = myCubeGrid.GetCubeBlock(cell); if (slim != null) { mutable.Add(slim); } return(false); }); myCubeGrid.OnBlockAdded += Grid_OnBlockAdded; myCubeGrid.OnBlockRemoved += Grid_OnBlockRemoved; myCubeGrid.OnClose += Grid_OnClose; using (lock_registry.AcquireExclusiveUsing()) registry.Add(this.myCubeGrid, this); }
public void List_AddItem_OnReadOnlyList_IsRejected() { var source = new List <int> { 13 }; var list = new ReadOnlyList <int>(source); list.Add(17); }
public void TestAddException() { var list = new List <int> { 7, 3, 5, 7, 20, 30 }; var readonlyList = new ReadOnlyList <int>(list); var exception = Assert.Throws <NotSupportedException>(() => readonlyList.Add(10)); Assert.Equal("Collection is read-only.", exception.Message); }