BinaryContainer2 1.0.2

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

Data Type Support:

Nullable, Boolean, Byte, Char, Decimal, Double, Guid, Int16, Int32, Int64, SByte, Single, String, UInt16, UInt32, UInt64.
DateTime, DateTimeOffset, TimeSpan.
Array, List, Stack, Queue, LinkedList, Multidimensional Array, IEnumerable.
KeyValuePair, Dictionary, SortedList, Tuple.
Enum, Class.
Object: where object is a build-in type, enum, or class.


Highlights:

Supports circular references, iterative references.
Supports polymorphism, inheritance.
Supports Dictionary with a Class Key.
Supports multi-level nested types.


Build

Passed: 692/692 test cases.
Version: .NET Standard 2.0


These are some real-world test cases that have passed

TEST CASE 1: Handling Circular Reference.
TEST CASE 2: Handling Inheritance and Polymorphism (Restoring subclass type).
TEST CASE 3: Handling Nulls, Empty Lists, and Decimal/DateTime Precision.
TEST CASE 5: Using DEEP nested structures (Recursion limit check).
TEST CASE 6: Handling Dictionary with a Class Key (Non-primitive Key).
TEST CASE 8: Serialization/Deserialization via Interface (Restoring actual type).
TEST CASE 9: Using a combination of List nested within a List and Default Values.
TEST CASE 10: Handling rare/difficult .NET Data Types (TimeSpan, Tuple, HashSet, 4-byte Unicode).
TEST CASE 13: Handling Duplicate Object Reference.
TEST CASE 14: Duplicate Reference in Collection.
TEST CASE 16: Using Nested NULL Data and Inheritance.
TEST CASE 18: Polymorphism in Collection (Restoring actual type of each item).
TEST CASE 19: Dictionary with Struct Value.
TEST CASE 20: Property with Object type (Maximum polymorphism).
...

How to use

var bin = BinConverter.GetBytes(target);
var item = BinConverter.GetItem<ItemType>(bin);

Performance comparison with JsonSerializer

Get bytes

Method Mean Error StdDev Median Gen0 Gen1 Allocated
GetBytes_SimpleObject 922.87 ns 18.327 ns 26.285 ns 922.98 ns 0.4063 0.0019 3400 B
JsonSerializer_SimpleObject 420.59 ns 8.150 ns 8.004 ns 417.81 ns 0.0191 - 160 B
GetBytes_ComplexObject 1,959.70 ns 23.159 ns 20.530 ns 1,952.94 ns 0.6447 0.0038 5400 B
JsonSerializer_ComplexObject 1,021.60 ns 20.506 ns 21.059 ns 1,019.33 ns 0.0763 - 640 B
GetBytes_SimpleList 38,655.29 ns 727.712 ns 996.100 ns 38,411.80 ns 8.8501 0.3052 74136 B
JsonSerializer_SimpleList 38,640.88 ns 543.558 ns 508.445 ns 38,413.91 ns 1.5259 - 12952 B
GetBytes_ComplexList 63,460.96 ns 1,194.750 ns 1,467.260 ns 63,554.36 ns 12.9395 0.7324 108672 B
JsonSerializer_ComplexList 49,888.94 ns 599.060 ns 500.242 ns 49,828.89 ns 1.8311 - 15488 B
GetBytes_Dictionary 9,541.98 ns 183.778 ns 211.639 ns 9,526.38 ns 2.3956 0.0305 20112 B
JsonSerializer_Dictionary 8,791.93 ns 171.792 ns 210.976 ns 8,789.13 ns 0.3510 - 3032 B
GetBytes_Null 90.39 ns 1.879 ns 4.241 ns 88.40 ns 0.0526 - 440 B
JsonSerializer_Null 96.02 ns 1.963 ns 3.921 ns 94.52 ns 0.0038 - 32 B
GetBytes_PrimitiveTypes 972.59 ns 19.039 ns 26.061 ns 974.05 ns 0.4158 - 3480 B
JsonSerializer_PrimitiveTypes 697.90 ns 13.506 ns 15.012 ns 696.78 ns 0.0296 - 248 B
GetBytes_LargeString 1,413.90 ns 29.511 ns 83.236 ns 1,385.06 ns 2.1820 0.0362 18272 B
JsonSerializer_LargeString 2,462.38 ns 50.605 ns 149.211 ns 2,456.63 ns 0.2022 - 1712 B
GetBytes_ArrayOfPrimitives 86,718.33 ns 1,385.149 ns 1,482.094 ns 86,772.27 ns 10.6201 0.3662 88944 B
JsonSerializer_ArrayOfPrimitives 18,335.04 ns 361.243 ns 386.525 ns 18,261.74 ns 1.3123 - 10992 B

Get item

Method Mean Error StdDev Gen0 Gen1 Allocated
GetItem_SimpleObject 823.66 ns 16.255 ns 25.307 ns 0.3462 0.0019 2896 B
JsonDeserialize_SimpleObject 688.69 ns 13.647 ns 13.404 ns 0.0124 - 104 B
GetItem_ComplexObject 2,423.26 ns 45.954 ns 86.313 ns 0.6714 0.0038 5632 B
JsonDeserialize_ComplexObject 2,082.58 ns 41.529 ns 62.159 ns 0.2098 - 1776 B
GetItem_SimpleList 41,131.37 ns 541.948 ns 452.551 ns 8.2397 0.4883 69107 B
JsonDeserialize_SimpleList 70,627.62 ns 799.426 ns 708.671 ns 1.5869 - 13864 B
GetItem_ComplexList 88,006.76 ns 1,658.766 ns 2,270.537 ns 15.8691 2.3193 132989 B
JsonDeserialize_ComplexList 103,485.21 ns 1,300.564 ns 1,086.030 ns 7.3242 0.9766 61432 B
GetItem_Dictionary 10,373.22 ns 167.814 ns 218.206 ns 2.3193 0.0458 19464 B
JsonDeserialize_Dictionary 16,022.08 ns 290.119 ns 345.366 ns 0.6104 - 5352 B
GetItem_Null 29.08 ns 0.769 ns 2.242 ns 0.0287 - 240 B
JsonDeserialize_Null 72.28 ns 1.282 ns 1.199 ns - - -
GetItem_LargeString 2,802.18 ns 56.014 ns 135.280 ns 1.6823 0.0191 14088 B
JsonDeserialize_LargeString 2,646.16 ns 50.467 ns 49.566 ns 0.4997 - 4208 B
GetItem_PrimitiveTypes 904.18 ns 17.955 ns 40.527 ns 0.3605 0.0019 3024 B
JsonDeserialize_PrimitiveTypes 930.20 ns 11.391 ns 10.098 ns 0.0257 - 216 B
GetItem_ArrayOfPrimitives 26,434.80 ns 521.064 ns 730.459 ns 8.4534 0.2747 70720 B
JsonDeserialize_ArrayOfPrimitives 47,628.61 ns 493.229 ns 411.869 ns 1.4648 - 12448 B

Output bytes size

Object bin converter bytes percent > json converter bytes percent
SimpleObject bindata(*) 61 48,412697 < jsondata 126
ComplexObject bindata(*) 215 68,910255 < jsondata 312
SimpleList bindata(*) 4285 33,937904 < jsondata 12626
ComplexList bindata(*) 9289 61,96798 < jsondata 14990
Dictionary bindata(*) 1010 37,49072 < jsondata 2694
Null bindata 5 > jsondata(*) 4 80
LargeString bindata(*) 1953 99,94882 < jsondata 1954
Primitive bindata(*) 90 38,29787 < jsondata 235
PrimitiveArr bindata(*) 4269 38,703537 < jsondata 11030
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.  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 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.2 172 10/31/2025
1.0.1 195 10/22/2025
1.0.0 204 10/19/2025