Yolofy.TupleTables 1.0.0

dotnet add package Yolofy.TupleTables --version 1.0.0                
NuGet\Install-Package Yolofy.TupleTables -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="Yolofy.TupleTables" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Yolofy.TupleTables --version 1.0.0                
#r "nuget: Yolofy.TupleTables, 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 Yolofy.TupleTables as a Cake Addin
#addin nuget:?package=Yolofy.TupleTables&version=1.0.0

// Install Yolofy.TupleTables as a Cake Tool
#tool nuget:?package=Yolofy.TupleTables&version=1.0.0                

TupleTables

Initialize a large collection of objects in a more readable way.

Example usage

 var table = TupleTable<Person>.Create
                  (p => p.Id,           p2 => p2.Name,  p3 => p3.Age,   p4 => p4.Gender,
                  (Guid.NewGuid(),      "Xumina",       15,             Gender.Female),
                  (Guid.NewGuid(),      "Bale",         26,             Gender.Male),
                  (Guid.NewGuid(),      "Robin",        30,             Gender.Neutral),
                  (Guid.NewGuid(),      "Adama",        25,             Gender.Female),
                  (Guid.NewGuid(),      "Theodore",     43,             Gender.Male),
                  (Guid.NewGuid(),      "Georgios",     82,             Gender.Male),
                  (Guid.NewGuid(),      "Anastasia",    14,             Gender.Female),
                  (Guid.NewGuid(),      "William",      39,             Gender.Male),
                  (Guid.NewGuid(),      "Yuina",        55,             Gender.Female),
                  (Guid.NewGuid(),      "Eden",         62,             Gender.Neutral));

Why?

Often in unit tests, there is a lot of data being initialized. The default for many developers is to use object initializers. But this quickly produces a hard to read piece of code:

var list = new List<Person>
                       {
                           new Person
                           {
                               Id     = Guid.NewGuid(),
                               Name   = "Xumina",
                               Age    = 15,
                               Gender = Gender.Female
                           },
                           new Person
                           {
                               Id     = Guid.NewGuid(),
                               Name   = "Bale",
                               Age    = 26,
                               Gender = Gender.Male
                           },
                           new Person
                           {
                               Id     = Guid.NewGuid(),
                               Name   = "Robin",
                               Age    = 30,
                               Gender = Gender.Neutral
                           },
                           new Person
                           {
                               Id     = Guid.NewGuid(),
                               Name   = "Adama",
                               Age    = 25,
                               Gender = Gender.Female
                           },
                           new Person
                           {
                               Id     = Guid.NewGuid(),
                               Name   = "Theodore",
                               Age    = 43,
                               Gender = Gender.Male
                           },
                           new Person
                           {
                               Id     = Guid.NewGuid(),
                               Name   = "Georgios",
                               Age    = 82,
                               Gender = Gender.Male
                           },
                           new Person
                           {
                               Id     = Guid.NewGuid(),
                               Name   = "Anastasia",
                               Age    = 14,
                               Gender = Gender.Female
                           },
                           new Person
                           {
                               Id     = Guid.NewGuid(),
                               Name   = "William",
                               Age    = 39,
                               Gender = Gender.Male
                           },
                           new Person
                           {
                               Id     = Guid.NewGuid(),
                               Name   = "Yuina",
                               Age    = 55,
                               Gender = Gender.Female
                           },
                           new Person
                           {
                               Id     = Guid.NewGuid(),
                               Name   = "Eden",
                               Age    = 62,
                               Gender = Gender.Neutral
                           }
                       };

Why not use the constructor?

The constructor isn't always available (e.g. not provided by a third party library). When it is, it forces you to provide every field in the constructor, in the right order.

 var list = List<Person>{
                  new Person(Guid.NewGuid(),      "Xumina",       15,    Gender.Female),
                  new Person(Guid.NewGuid(),      "Bale",         26,    Gender.Male),
                  new Person(Guid.NewGuid(),      "Robin",        30,    Gender.Neutral),
                  new Person(Guid.NewGuid(),      "Adama",        25,    Gender.Female),
                  new Person(Guid.NewGuid(),      "Theodore",     43,    Gender.Male),
                  new Person(Guid.NewGuid(),      "Georgios",     82,    Gender.Male),
                  new Person(Guid.NewGuid(),      "Anastasia",    14,    Gender.Female),
                  new Person(Guid.NewGuid(),      "William",      39,    Gender.Male),
                  new Person(Guid.NewGuid(),      "Yuina",        55,    Gender.Female),
                  new Person(Guid.NewGuid(),      "Eden",         62,    Gender.Neutral)};

Why not use a (helper / collection initializer) method

You need to write one for every type, and it forces you to provide every field in the method, in the right order.

static class PersonExtensions
{
   public static void Add(this ICollection<Person> l, Guid id, String name, Int age, Gender gender)
     => l.Add(new Person { Id = id, Name = name, Age = age, Gender = gender });
}

var table = Table = new List<Person>
        {
            { Guid.NewGuid(),      "Xumina",       15,    Gender.Female},
            { Guid.NewGuid(),      "Bale",         26,    Gender.Male},
            { Guid.NewGuid(),      "Robin",        30,    Gender.Neutral},
            { Guid.NewGuid(),      "Adama",        25,    Gender.Female},
            { Guid.NewGuid(),      "Theodore",     43,    Gender.Male},
            { Guid.NewGuid(),      "Georgios",     82,    Gender.Male},
            { Guid.NewGuid(),      "Anastasia",    14,    Gender.Female},
            { Guid.NewGuid(),      "William",      39,    Gender.Male},
            { Guid.NewGuid(),      "Yuina",        55,    Gender.Female},
            { Guid.NewGuid(),      "Eden",         62,    Gender.Neutral}
        };
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.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • 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 563 5/30/2019

Initial release