Org.Grush.Lib.RecordCollections 0.0.1-rc.7-split-validation

This is a prerelease version of Org.Grush.Lib.RecordCollections.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Org.Grush.Lib.RecordCollections --version 0.0.1-rc.7-split-validation
                    
NuGet\Install-Package Org.Grush.Lib.RecordCollections -Version 0.0.1-rc.7-split-validation
                    
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="Org.Grush.Lib.RecordCollections" Version="0.0.1-rc.7-split-validation" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Org.Grush.Lib.RecordCollections" Version="0.0.1-rc.7-split-validation" />
                    
Directory.Packages.props
<PackageReference Include="Org.Grush.Lib.RecordCollections" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Org.Grush.Lib.RecordCollections --version 0.0.1-rc.7-split-validation
                    
#r "nuget: Org.Grush.Lib.RecordCollections, 0.0.1-rc.7-split-validation"
                    
#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.
#:package Org.Grush.Lib.RecordCollections@0.0.1-rc.7-split-validation
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Org.Grush.Lib.RecordCollections&version=0.0.1-rc.7-split-validation&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Org.Grush.Lib.RecordCollections&version=0.0.1-rc.7-split-validation&prerelease
                    
Install as a Cake Tool

RecordCollection<T>

A read-only, equatable, de/serializable, generic collection type for use in record classes.

Initialization

RecordCollections can be initialized using the new collection expression approach:

RecordCollection<double> c = [3.14159, double.NaN, double.PositiveInfinity];

or using the static Create methods, e.g.

var a = RecordCollection.Create(["a", "b", "c"]);

or using the LINQ-like extension on an existing IEnumerable:

List<int> oldList = [1, 2, 3];
var a = oldList.ToRecordCollection();

Equating

Two RecordCollections that are sequence-equal will return true from Equals():

RecordCollection<int> collectionA = [1, 2, 3];
var collectionB = RecordCollection.Create([1, 2, 3]);

var areEqual = collectionA.Equals(collectionB);

areEqual.Should().BeTrue();

This means that two records that contain RecordCollection<T> properties are still equatable

record MyRecord(string Name, RecordCollection<string> Aliases);

MyRecord a = new("Joseph", ["Joe", "Joey"]);
MyRecord b = new("Joseph", ["Joe", "Joey"]);

var areEqual = a.Equals(b);

areEqual.Should().BeTrue();

additionally, RecordCollection<T>s can be used in hash structures like HashSets:

HashSet<RecordCollection<double>> set = [
  [1.1, 2.2]
];

var contains = set.Contains([1.1, 2.2]);

contains.Should().BeTrue();

Serialization

Serialization is implicitly supported by both System.Text.Json and Newtonsoft.

Deserialization

System.Text.Json

Reflection-based serialization is supported implicitly.

For AOT-compatible serialization the RecordCollectionStrictJsonConverter<T> is provided by the core package:

using System.Text.Json;
using System.Text.Json.Serialization;
using Org.Grush.Lib.RecordCollections;

namespace TestProgram;

string jsonData =
  """
  [{ "Name": "Joseph", "Alias": "Joey" }, { "Name": "Tom" }]
  """;

RecordCollection<Datum>? data = JsonSerializer.Deserialize(
  json: jsonData,
  jsonTypeInfo: RecordCollectionOfDataContext.Default.RecordCollectionDatum
);



record Datum(string Name, string? Alias);

[JsonSourceGenerationOptions(WriteIndented = true, Converters = [typeof(RecordCollectionStrictJsonConverter<Datum>)])]
[JsonSerializable(typeof(RecordCollection<Datum>))]
[JsonSerializable(typeof(ImmutableArray<Datum>))]
[JsonSerializable(typeof(Datum))]
internal partial class RecordCollectionOfDataContext : JsonSerializerContext;

Newtonsoft

Newtonsoft deserialization is supported using the supplementary Org.Grush.Lib.RecordCollections.Newtonsoft package, either with the generic RecordCollectionNewtonsoftJsonConverterFactory, or if a specific type is known then RecordCollectionNewtonsoftJsonConverter<T> converter can be used directly.

using Newtonsoft.Json;
using Org.Grush.Lib.RecordCollections.Newtonsoft;

namespace TestProgram;

string jsonData =
  """
  {
    "Strings": ["a", "b"],
    "Ints": [1, 2]
  }
  """;

PairOfLists? pair1 = JsonConvert.DeserializeObject<PairOfLists>(jsonData, new JsonSerializerSettings
{
  Converters = { new RecordCollectionNewtonsoftJsonConverterFactory() }
});

PairOfLists? pair2 = JsonConvert.DeserializeObject<PairOfLists>(jsonData, new JsonSerializerSettings
{
  Converters = {
    new RecordCollectionNewtonsoftJsonConverter<int>(),
    new RecordCollectionNewtonsoftJsonConverter<string>(),
  }
});

record PairOfLists(RecordCollection<string> Strings, RecordCollection<int> Ints);
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 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Org.Grush.Lib.RecordCollections:

Package Downloads
Org.Grush.Lib.RecordCollections.Newtonsoft

Newtonsoft add-on for serializing Org.Grush.Lib.RecordCollections.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0 143 2/5/2025
0.2.1 120 1/30/2025
0.1.0 129 1/29/2025
0.0.1-rc.7-split-validation 72 1/29/2025
0.0.0-PR 100 1/30/2025