Soenneker.Extensions.Dictionary 4.0.672

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

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Extensions.Dictionary

Extensions for flattening dictionary values, merging keyed objects, mapping string/object data to objects, and reverse value lookup.

Installation

dotnet add package Soenneker.Extensions.Dictionary

Flatten lists of values

using Soenneker.Extensions.Dictionary;

var groups = new Dictionary<string, List<int>>
{
    ["odd"] = [1, 3],
    ["even"] = [2, 4]
};

List<int> values = groups.ToFlattenedValuesList(); // 1, 3, 2, 4

The result follows dictionary enumeration order and then each list's order. Null lists are skipped, and the source lists are not changed.

Add or update ranges

var people = new[]
{
    new Person("a", "Alice"),
    new Person("b", "Bob")
};

var byId = new Dictionary<string, Person>();
byId.AddRange(people, person => person.Id);

public sealed record Person(string Id, string Name);

AddRange() compiles the expression selector on each call. Use AddRangeCompiled() with a reusable Func<TValue, TKey> in repeated or hot paths. Both methods mutate the destination, add missing keys, and replace existing values. If multiple input items produce the same key, the last item wins.

AddDictionary(source, dictionary) applies the same add-or-replace behavior to every entry from another dictionary.

Map a dictionary to an object

var data = new Dictionary<string, object>
{
    ["name"] = "Jane",
    ["Age"] = "42"
};

PersonDto person = data.ToObject<PersonDto>();
// person.Name == "Jane"
// person.Age == 42

public sealed class PersonDto
{
    public string? Name { get; set; }
    public int Age { get; set; }
}

Property names are matched case-insensitively. Directly assignable values are used as-is; otherwise, Convert.ChangeType is attempted. Unknown properties, read-only properties, nulls that cannot be assigned, and values that fail ordinary type conversion are skipped. This is a lightweight mapper, not a serializer: nested objects, collections, enums, and nullable conversions may require explicit preparation.

Find a key by value

bool found = byId.TryGetKeyFromValue(people[0], out string? key);

TryGetKeyFromValue() uses reference equality first and then Equals. When several keys have equal values, it returns the first match in dictionary enumeration order. When no value matches, it returns false and sets the output key to its default value.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in 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
4.0.672 43 9/25/2026
4.0.671 41 9/24/2026
4.0.670 174 9/16/2026
4.0.669 126 9/16/2026
4.0.668 92 9/15/2026
4.0.667 119 9/15/2026
4.0.666 170 9/12/2026
4.0.665 88 9/12/2026
4.0.664 101 9/12/2026
4.0.662 124 9/12/2026
4.0.661 178 9/8/2026
4.0.660 190 9/7/2026
4.0.659 175 9/4/2026
4.0.658 111 9/3/2026
4.0.657 106 9/2/2026
4.0.656 117 9/2/2026
4.0.655 111 9/2/2026
4.0.654 120 9/1/2026
4.0.653 102 9/1/2026
4.0.652 120 9/1/2026
Loading failed

Updated NuGet packages