ToolBX.Collections.Grid
1.0.0
See the version list below for details.
dotnet add package ToolBX.Collections.Grid --version 1.0.0
NuGet\Install-Package ToolBX.Collections.Grid -Version 1.0.0
<PackageReference Include="ToolBX.Collections.Grid" Version="1.0.0" />
paket add ToolBX.Collections.Grid --version 1.0.0
#r "nuget: ToolBX.Collections.Grid, 1.0.0"
// Install ToolBX.Collections.Grid as a Cake Addin
#addin nuget:?package=ToolBX.Collections.Grid&version=1.0.0
// Install ToolBX.Collections.Grid as a Cake Tool
#tool nuget:?package=ToolBX.Collections.Grid&version=1.0.0
Collections
Modern and straightforward .NET Collections
ObservableList
An observable, dynamic one-dimensional array.
Ever wish C#'s list would tell you if it has been modified in any way without having to clumsily wrap it like so
private readonly List<Thing> _things = new List<Thing>();
public void Add(Thing thing)
{
_things.Add(thing);
DoStuff();
}
This is where ObservableList shines the brightest.
private readonly ObservableList<Thing> _things = new ObservableList<Thing>();
public void SomeInitializationMethodSomewhere()
{
_things.CollectionChanged += OnThingsChanged;
}
//This gets called whenever the ObservableList is changed be it through Add, Insert, Remove, RemoveAt, Clear, etc...
private void OnThingsChanged(object sender, CollectionChangeEventArgs<Thing> args)
{
foreach (var item in args.OldValues)
{
DoStuffWithOldValues();
}
foreach (var item in args.NewValues)
{
DoStuffWithNewValues();
}
}
Grid
An observable, dynamic two-dimensional array.
Which one should you use? T[,] or T[][]? What is the difference? How do you instantiate this again? Use Grid<T>!
Grid<T> is to T[,] what ObservableList<T> is to T[]. It's easy to use and, as a bonus, is observable as well!
Unlike 2D arrays, it does support negative indexes. In other words, the following is allowed:
grid[-13, 4] = "thingy";
Getting started
//Instantiation
var grid = new Grid<string>();
//You don't need to specify the grid's boundaries as it'll "expand" automatically
grid[20, 45] = "Something";
//Deconstructors are provided for the cell
foreach (var ((x, y), value) in grid)
{
...
}
//You can also just iterate through it like this if you're old school and systematically hate syntaxic sugar that came out after 201X
foreach (var cell in grid)
{
if (cell.Index.X > 0)
{
...
}
}
//You can also listen for changes
grid.CollectionChanged += OnGridChanged;
//This will flood fill the grid starting with the index that was passed and will automatically stop at the grid's current boundaries
grid.FloodFill(4, 5, "ToolBX!");
//Or you can specify boundaries manually if you want to go over (or under) its limits
grid.FloodFill(4, 5, "ToolBX!", new Boundaries<int> { Top = -10, Left = -5, Bottom = 40, Right = 80 });
//You can even clear all of that up
grid.FloodClear(10, 5);
It even has equality overloads so that you're not merely comparing references whenever you test for equality. Not only that but it also has overloads for most similar types such as dictionaries, 2d arrays and even jagged arrays.
And extension methods!
//You can also make a 2d array out of it if that's your thing
var array = grid.To2dArray();
//Or turn a 2d array into a grid
var grid = array.ToGrid();
//Yep, even jagged arrays if you like those! I'm not judging! (I am)
var jagged = grid.ToJaggedArray();
//And also turn it back into a grid!
grid = jagged.ToGrid();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- ToolBX.EasyTypeParsing (>= 1.0.0)
- ToolBX.Mathemancy (>= 1.0.1)
- ToolBX.Reflection4Humans.Extensions (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ToolBX.Collections.Grid:
Package | Downloads |
---|---|
ToolBX.Collections.UnitTesting
Tester classes and extensions to help with unit testing ToolBX.Collections. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.2.0 | 160 | 1/13/2024 |
2.2.0-beta2 | 93 | 1/7/2024 |
2.2.0-beta1 | 67 | 1/4/2024 |
2.0.5-beta1 | 96 | 7/10/2023 |
2.0.4 | 177 | 6/19/2023 |
2.0.3 | 232 | 4/27/2023 |
2.0.2 | 270 | 1/18/2023 |
2.0.1 | 306 | 11/15/2022 |
2.0.0 | 307 | 11/11/2022 |
2.0.0-beta3 | 140 | 11/3/2022 |
2.0.0-beta2 | 117 | 10/3/2022 |
2.0.0-beta1 | 151 | 9/22/2022 |
1.1.2-beta1 | 132 | 11/3/2022 |
1.1.1 | 408 | 9/21/2022 |
1.1.0 | 400 | 9/16/2022 |
1.1.0-beta1 | 112 | 8/29/2022 |
1.0.4 | 402 | 8/8/2022 |
1.0.3 | 407 | 7/11/2022 |
1.0.2 | 394 | 4/28/2022 |
1.0.1 | 415 | 2/28/2022 |
1.0.0 | 389 | 2/11/2022 |