3Scribe.Utilities.CrossRefCollection 1.0.0

dotnet add package 3Scribe.Utilities.CrossRefCollection --version 1.0.0                
NuGet\Install-Package 3Scribe.Utilities.CrossRefCollection -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="3Scribe.Utilities.CrossRefCollection" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add 3Scribe.Utilities.CrossRefCollection --version 1.0.0                
#r "nuget: 3Scribe.Utilities.CrossRefCollection, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install 3Scribe.Utilities.CrossRefCollection as a Cake Addin
#addin nuget:?package=3Scribe.Utilities.CrossRefCollection&version=1.0.0

// Install 3Scribe.Utilities.CrossRefCollection as a Cake Tool
#tool nuget:?package=3Scribe.Utilities.CrossRefCollection&version=1.0.0                

CrossRefCollection

CrossReference<TRows, TColumns, TData>

Add a generic collection called CrossReference to the System.Collections.Generic namespace that allows for creation of a multi-dimensional keyed dictionary. Values in the table are accessed by providing a row and column key. For example, if you had a collection called PrimaryColours with the following data saved in it:

Red Green Blue
Red Yellow Magenta
Yellow Green Cyan
Magenta Cyan Blue

then the following reference PrimaryColours["Blue", "Green"] will return "Cyan". The collection allows for strongly typing the row key, column key and data values when initialising, e.g.

CrossReference<string, int, bool> _TestTable = new CrossReference<string, int, bool>();

creates a collection where the row keys are strings, the column keys are integers and the data values are booleans i.e.

1 2 3
true false false
false true false
false false true

with ["X",3] = false and ["Y", 2] = true.

Set Up

The package is available on NuGet here

As this is an extention to the System.Collections.Generic namespace only that specific library will be required:

using System.Collections.Generic;

Initialising

There are a number of ways to create and load values in to the collection.

Example 1

Initialising a blank object and then passing a complete object[,] to the Table parameter to fill in row and column keys and all data values. In this example the table data represents the bit rate of an MP3 based on values taken from the header of the MP3 file. The column headers represent the MPEG version and the 'Layer' and the rows represent the 4 bits taken from the file that denote the bitrate of the audio.

CrossReference<int, int, int> _TestTable = new CrossReference<int, int, int>();

_TestTable.Table = new object[,]
{
    { null, 1111, 1110, 1101, 1011, 1010, 1001 },
    { 0000,    0,    0,    0,    0,    0,    0 },
    { 0001,   32,   32,   32,   32,    8,    8 },
    { 0010,   64,   48,   40,   48,   16,   16 },
    { 0011,   96,   56,   48,   56,   24,   24 },
    { 0100,  128,   64,   56,   64,   32,   32 },
    { 0101,  160,   80,   64,   80,   40,   40 },
    { 0110,  192,   96,   80,   96,   48,   48 },
    { 0111,  224,  112,   96,  112,   56,   56 },
    { 1000,  256,  128,  112,  128,   64,   64 },
    { 1001,  288,  160,  128,  144,   80,   80 },
    { 1010,  320,  192,  160,  160,   96,   96 },
    { 1011,  352,  224,  192,  176,  112,  112 },
    { 1100,  384,  256,  224,  192,  128,  128 },
    { 1101,  416,  320,  256,  224,  144,  144 },
    { 1110,  448,  384,  320,  256,  160,  160 },
    { 1111,   -1,   -1,   -1,   -1,   -1,   -1 }
};

Example 2

This is a simple 3x3 grid with a string as the row key, an int as the column key and booleans as the data type. After the grid has been initialised and 3 of the falues changed to true (the default value of the data will be false) new columns keys are set which has the effect of resetting all of the data.

CrossReference<string, int, bool> _TestTableB = new CrossReference<string, int, bool>(new string[] { "A", "B", "C" }, new int[] { 1, 2, 3 });

_TestTableB["A", 1] = true;
_TestTableB["B", 2] = true;
_TestTableB["C", 3] = true;

_TestTableB.Columns = new List<int>() { 9, 8, 7 };

Example 3

This is a similiar example to the previous one but it demonstrates a different method for setting and resetting the column keys. Row keys can be reset in the exact same way.

CrossReference<string, string, double> _TestTableC = new CrossReference<string, string, double>();

_TestTableC.AddColumns(new string[] { "X", "Y", "Z" });
_TestTableC.AddRows(new string[] { "X", "Y", "Z" });

_TestTableC["X", "Z"] = 1.5;
_TestTableC["Y", "Y"] = 1.5;
_TestTableC["Z", "X"] = 1.5;

_TestTableC.AddColumns("A", "B", "C");

_TestTableC["X", "A"] = 2.1;
_TestTableC["Y", "B"] = 2.1;
_TestTableC["Z", "C"] = 2.1;

Additional Methods

Clear

.Clear() resets the collection, removing any row keys, column keys and data.

Keys

.Rows() and .Columns() return a List collection, strongly types to the row and column key types declared.

.ContainsRowKey(TRows key) and .ContainsColumnKey(TColumns key) return a boolean to indicate if the passed key value exists in the respective collection.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 1,299 1/6/2019
0.9.0 1,052 1/2/2019

1.0.0 Initial Release