Soenneker.Extensions.Dictionary
4.0.652
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Extensions.Dictionary --version 4.0.652
NuGet\Install-Package Soenneker.Extensions.Dictionary -Version 4.0.652
<PackageReference Include="Soenneker.Extensions.Dictionary" Version="4.0.652" />
<PackageVersion Include="Soenneker.Extensions.Dictionary" Version="4.0.652" />
<PackageReference Include="Soenneker.Extensions.Dictionary" />
paket add Soenneker.Extensions.Dictionary --version 4.0.652
#r "nuget: Soenneker.Extensions.Dictionary, 4.0.652"
#:package Soenneker.Extensions.Dictionary@4.0.652
#addin nuget:?package=Soenneker.Extensions.Dictionary&version=4.0.652
#tool nuget:?package=Soenneker.Extensions.Dictionary&version=4.0.652
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 | Versions 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. |
-
net10.0
- Soenneker.Reflection.Cache (>= 4.0.673)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Extensions.Dictionary:
| Package | Downloads |
|---|---|
|
Soenneker.Swashbuckle.Authentication
A middleware implementing basic authentication and RBAC support for Swashbuckle (Swagger) |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.659 | 34 | 9/4/2026 |
| 4.0.658 | 41 | 9/3/2026 |
| 4.0.657 | 43 | 9/2/2026 |
| 4.0.656 | 53 | 9/2/2026 |
| 4.0.655 | 49 | 9/2/2026 |
| 4.0.654 | 57 | 9/1/2026 |
| 4.0.653 | 42 | 9/1/2026 |
| 4.0.652 | 58 | 9/1/2026 |
| 4.0.651 | 88 | 8/31/2026 |
| 4.0.650 | 127 | 8/31/2026 |
| 4.0.649 | 82 | 8/31/2026 |
| 4.0.648 | 151 | 8/30/2026 |
| 4.0.647 | 78 | 8/30/2026 |
| 4.0.646 | 77 | 8/30/2026 |
| 4.0.645 | 77 | 8/30/2026 |
| 4.0.644 | 79 | 8/29/2026 |
| 4.0.643 | 80 | 8/29/2026 |
| 4.0.642 | 82 | 8/29/2026 |
| 4.0.641 | 85 | 8/29/2026 |
| 4.0.640 | 204 | 8/27/2026 |
Updated NuGet packages
- [Soenneker.Reflection.Cache](Soenneker.Reflection.Cache): [4.0.672](Soenneker.Reflection.Cache/4.0.672) -> [4.0.673](Soenneker.Reflection.Cache/4.0.673)