GordoSoft.ChunkyMonkey 1.0.12

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package GordoSoft.ChunkyMonkey --version 1.0.12
                    
NuGet\Install-Package GordoSoft.ChunkyMonkey -Version 1.0.12
                    
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="GordoSoft.ChunkyMonkey" Version="1.0.12" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GordoSoft.ChunkyMonkey" Version="1.0.12" />
                    
Directory.Packages.props
<PackageReference Include="GordoSoft.ChunkyMonkey" />
                    
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 GordoSoft.ChunkyMonkey --version 1.0.12
                    
#r "nuget: GordoSoft.ChunkyMonkey, 1.0.12"
                    
#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 GordoSoft.ChunkyMonkey@1.0.12
                    
#: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=GordoSoft.ChunkyMonkey&version=1.0.12
                    
Install as a Cake Addin
#tool nuget:?package=GordoSoft.ChunkyMonkey&version=1.0.12
                    
Install as a Cake Tool

ChunkyMonkey - C# Object Chunking Source Generator

Introduction

ChunkyMonkey is a C# Code Generator to split a class containing list, array, collection or dictionary properties into chunks. It also provides the ability to merge the chunks back into a single instance.

Use Cases

  • You need to break down a large API request into smaller pieces - to avoid breaking the maximum request body size limit of your web server.

Walkthrough

Imagine you have a class like this:

public class CreateUserRequest
{
	public string Username { get; set; }
	public DateTime DateOfBirth { get; set; }	
	public List<int> FavouriteNumbers { get; set; }
	public string[] FavouriteFilms { get; set; }
	public Dictionary<string, string> Attributes { get; set; }
}

If the user has a lot of favourite numbers, films and attributes, you may want to split the class into chunks to reduce the size of the request object. [Yes, this is a very contrived example!]

ChunkyMonkey generates two methods within partial classes, where T is the name of the class.

The method isn't generic. The generated code contains the actual class type rather than T.

public IEnumerable<T> Chunk(int chunkSize)
public T MergeChunks(IEnumerable<T> chunks)

IEnumerable<T> Chunk(int chunkSize)

  • Only partial classes can be chunked. This is because the code generates generates a partial class containing the methods above for each chunked class.
  • Non-chunkable properties are repeated for each chunked instance.
  • If a collection (list, collection, array or dictionary) property's values are exhausted, subsequent chunks will contain an empty collection for the property value.

Example of usage

Input to Chunks(3)
Property Value
Username 'bob'
DateOfBirth 1/2/1975
FavouriteNumbers [1, 2, 3, 4, 5, 6, 7]
FavouriteFilms ['E.T.', 'Flight of the Navigator', 'Weird Science', 'Ferris Bueller�s Day Off', 'Ghostbusters']
Attributes {<br> 'Eye Colour': 'Blue',<br> 'Hair Colour': 'Brown',<br> 'Height (cm)': '180',<br> 'First Language': 'English'<br> }
Output for Chunks(3)

Chunk #1

Property Value
Username 'bob'
DateOfBirth 1/2/1975
FavouriteNumbers [1, 2, 3]
FavouriteFilms ['E.T.', 'Flight of the Navigator', 'Weird Science']
Attributes {<br> 'Eye Colour': 'Blue',<br> 'Hair Colour': 'Brown',<br> 'Height (cm)': '180',<br> }

Chunk #2

Property Value
Username 'bob'
DateOfBirth 1/2/1975
FavouriteNumbers [4, 5, 6]
FavouriteFilms ['Ferris Bueller�s Day Off', 'Ghostbusters']
Attributes {<br> 'First Language': 'English'<br> }

Chunk #3

Property Value
Username 'bob'
DateOfBirth 1/2/1975
FavouriteNumbers [7]
FavouriteFilms []
Attributes {}

T MergeChunks(IEnumerable<T> chunks)

This generated method merges a set of chunks back into a single instance.

Limitations

  • Does not currrently support nullable types.

Future Enhancements

  • Handle nullable reference types
  • Check Chunk method doesn't already exist
  • Check MergeChunks method doesn't already exist
  • Check that the existing class is a partial class (if not, compiler warning)
  • Check that the existing class is not sealed (if so, compiler warning)
  • Check that the existing class is not static (if so, compiler warning)
  • Check that the existing class is not abstract (if so, compiler warning)
  • Check that the existing class is not a struct (if so, compiler warning)
  • Check that the existing class has a parameterless constructor (if not, compiler warning)
  • Check that the existing class has a public constructor (if not, compiler warning)
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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

Initial release