Org.Grush.Lib.RecordCollections
0.0.1-rc.7-split-validation
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
<PackageReference Include="Org.Grush.Lib.RecordCollections" Version="0.0.1-rc.7-split-validation" />
<PackageVersion Include="Org.Grush.Lib.RecordCollections" Version="0.0.1-rc.7-split-validation" />
<PackageReference Include="Org.Grush.Lib.RecordCollections" />
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"
#:package Org.Grush.Lib.RecordCollections@0.0.1-rc.7-split-validation
#addin nuget:?package=Org.Grush.Lib.RecordCollections&version=0.0.1-rc.7-split-validation&prerelease
#tool nuget:?package=Org.Grush.Lib.RecordCollections&version=0.0.1-rc.7-split-validation&prerelease
RecordCollection<T>
A read-only, equatable, de/serializable, generic collection type for use in record classes.
Initialization
RecordCollection
s 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 RecordCollection
s 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 HashSet
s:
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 | Versions 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. |
-
.NETStandard 2.1
- System.Collections.Immutable (>= 8.0.0 && < 10.0.0)
- System.Text.Json (>= 8.0.5 && < 10.0.0)
-
net8.0
- No dependencies.
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 |