Sunlighter.TypeTraitsLib 1.0.1

dotnet add package Sunlighter.TypeTraitsLib --version 1.0.1
                    
NuGet\Install-Package Sunlighter.TypeTraitsLib -Version 1.0.1
                    
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="Sunlighter.TypeTraitsLib" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sunlighter.TypeTraitsLib" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Sunlighter.TypeTraitsLib" />
                    
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 Sunlighter.TypeTraitsLib --version 1.0.1
                    
#r "nuget: Sunlighter.TypeTraitsLib, 1.0.1"
                    
#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.
#addin nuget:?package=Sunlighter.TypeTraitsLib&version=1.0.1
                    
Install Sunlighter.TypeTraitsLib as a Cake Addin
#tool nuget:?package=Sunlighter.TypeTraitsLib&version=1.0.1
                    
Install Sunlighter.TypeTraitsLib as a Cake Tool

TypeTraitsLib

This is a type traits library that allows for comparison, hashing, and serialization of a wide variety of C# types, including immutable collections. The central interface is ITypeTraits<T>. There are many extension methods, singleton classes which implement the traits for various values of T, and some classes for tuples and immutable collections. There are also classes for union types, record types, and types which might be self-referential (see RecursiveTypeTraits<T>.) It is also possible to implement ITypeTraits<T> directly.

Although generally designed for immutable types, the library also supports StrongBox<T> and user-defined mutable box types. Mutable boxes can be used to create circular references, which are serialized correctly but verbosely: the library may serialize a second copy before detecting a circular reference.

There is also code to send serialized objects as blobs over TCP, and to set up servers and clients.

This implementation of the traits library has traits for System.Type and System.Assembly which are generally intended to allow types to be used, for example, as keys in immutable sorted dictionaries. However, the traits would allow instances of these types to be serialized and deserialized, and it might be dangerous to deserialize a file where an attacker could have specified an arbitrary type or assembly to deserialize. It should be noted that I do not have any code that loads assemblies as a result of deserialization. You can only deserialize an assembly if it is already loaded. If the deserialized data specifies an assembly which is not loaded, an exception will be thrown during deserialization. But I do not know if this is sufficient to ensure security.

I have seen some cases where the same assembly seems to be loaded twice, but types from one loading do not seem to be equivalent to types from the other loading. (This seems to only happen when running tests, and it only affects certain test-related assemblies which are probably used internally by the test framework but would probably not be used by normal tests or by the code being tested — but even if they are used, you probably wouldn’t want to create traits for these types and try to serialize instances of these types, etc.) The traits classes, as currently written, will not be able to work with types where the assembly cannot be uniquely identified.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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 is compatible.  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 is compatible.  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. 
.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.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Sunlighter.TypeTraitsLib:

Package Downloads
Sunlighter.LexerGenLib

Lexer Generator Library

Sunlighter.FrayedKnot

Library for Rope data type

Sunlighter.LrParserGenLib

LR(1) Parser Generator Library

Sunlighter.ShelfLib

Persistent dictionary using Sunlighter.TypeTraitsLib and SQLite

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 209 4/7/2025
1.0.0 144 4/7/2025