CommonNetFuncs.FastMap 5.0.0

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

CommonNetFuncs.FastMap

License NuGet Version NuGet downloads

Expression-tree mapping for net11.0 and netstandard2.1.

Contents

Installation

dotnet add package CommonNetFuncs.FastMap
using CommonNetFuncs.Core;
using CommonNetFuncs.FastMap;

FastMap

Both public overloads are demonstrated below:

public sealed class Child
{
    public string Value { get; set; } = string.Empty;
}

public sealed class Source
{
    public string Name { get; set; } = string.Empty;
    public Child SourceChild { get; set; } = new();
    public List<int> Values { get; set; } = [];
}

public sealed class Destination
{
    public Destination() { } // Destination types require a public parameterless constructor.
    public string? Name { get; set; }
    public Child SourceChild { get; set; } = new(); // Same type: assigned directly.
    public List<int>? Values { get; set; }
    public string? MissingInSource { get; set; }
}

Source source = new() { Name = "Ada", Values = [1, 2] };

Destination? staticCached = source.FastMap<Source, Destination>();
Destination? configuredCached = source.FastMap<Source, Destination>(useCache: true);
Destination? uncached = source.FastMap<Source, Destination>(useCache: false);
Destination? fromNull =
    ((Source?)null).FastMap<Source, Destination>();

The default overload uses a static generic cache that cannot be cleared at runtime. The useCache: true overload uses FastMapper.CacheManager; false compiles a mapper for that call. A null source returns null.

Mapping is by exact property name, without string case conversion or custom profiles. A destination property is assigned only when it is writable, the source property is readable, and the property types are supported. Missing, read-only, or incompatible properties retain their destination initializer/default value. Public destination construction must succeed (new TDest() is used in the expression).

Supported shapes:

  • Same-type scalar/object properties are assigned directly. Same-type nested reference objects are not cloned.
  • Different nested class types are recursively mapped by matching properties and guarded for null.
  • Arrays, List<T>, HashSet<T>, and other IEnumerable source shapes can be converted to array/list/hash-set destinations.
  • Elements with different types are mapped recursively. Same-type element collections are copied into a new array/list/hash set (or into a list for the generic fallback), but reference elements are still shared.
  • Dictionary key types must match. Same value types produce a new dictionary; different value types are mapped. Null dictionary values are preserved as null.

Unsupported destination collection shapes can cause expression-construction/compile errors. For example, a Queue<T>/Stack<T> property should not be assumed to work as a destination. Cycles are not tracked. Value-only and collection conversions may throw from expression compilation, constructors, incompatible key types, or mapping of unsupported types. The default static-cache path can wrap first-time construction failures in TypeInitializationException.

public sealed record SourceItem(string Name);
public sealed class DestinationItem
{
    public string? Name { get; set; }
}

SourceItem[] rows = [new("A"), new("B")];
DestinationItem[] mapped =
    rows.FastMap<SourceItem[], DestinationItem[]>()!;

Dictionary<string, SourceItem> byId = new()
{
    ["a"] = new("A")
};
Dictionary<string, DestinationItem> mappedById =
    byId.FastMap<Dictionary<string, SourceItem>,
        Dictionary<string, DestinationItem>>()!;

This mapper does not validate, sanitize, authorize, or deep-clone privileged data. Do not map an untrusted object directly into fields a caller may not set; use an explicit DTO/projection.

Cache management

FastMapper.CacheManager exposes Core's ICacheManagerApi<MapperCacheKey, Delegate>. ClearCache() clears only the managed cache; it cannot remove mappers already stored in the default overload's per-generic-type static cache.

FastMapper.CacheManager.SetLimitedCacheSize(50);
FastMapper.CacheManager.SetUseLimitedCache(true);

FastMapper.MapperCacheKey key = new(typeof(Source), typeof(Destination));
bool same = key == new(typeof(Source), typeof(Destination));
bool different = key != new(typeof(Source), typeof(object));
bool equalByMethod = key.Equals(new(typeof(Source), typeof(Destination)));
bool equalByObject = key.Equals(
    (object)new FastMapper.MapperCacheKey(
        typeof(Source),
        typeof(Destination)));
int hash = key.GetHashCode();
Console.WriteLine($"{key.SourceType.Name} -> {key.DestType.Name}");

FastMapper.CacheManager.ClearAllCaches();
FastMapper.ClearCache(); // Same managed caches; not static generic caches.

var cacheView = FastMapper.CacheManager.GetCache();
var limitedView = FastMapper.CacheManager.GetLimitedCache();
int cacheSize = FastMapper.CacheManager.GetLimitedCacheSize();
bool isLimited = FastMapper.CacheManager.IsUsingLimitedCache();
FastMapper.CacheManager.SetUseLimitedCache(false);
Delegate mapper = FastMapper.CacheManager.GetOrAddCache(
    key,
    _ => (Func<Source, Destination>)(value => new Destination()));
bool added = FastMapper.CacheManager.TryAddCache(
    new(typeof(Source), typeof(Destination)),
    mapper);
_ = FastMapper.CacheManager.GetOrAddLimitedCache(key, _ => mapper);
_ = FastMapper.CacheManager.TryAddLimitedCache(
    new(typeof(Source), typeof(Destination)),
    mapper);
FastMapper.CacheManager.ClearCache();
FastMapper.CacheManager.ClearLimitedCache();
FastMapper.CacheManager.ClearAllCaches(); // Remove demonstration delegates.

MapperCacheKey is a readonly struct with a two-Type constructor, public SourceType/DestType fields, typed and object equality overloads, GetHashCode, and ==/!=.

License

MIT. See LICENSE.

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.  net11.0 is compatible. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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 (1)

Showing the top 1 NuGet packages that depend on CommonNetFuncs.FastMap:

Package Downloads
CommonNetFuncs.Web.Api

Generic API endpoints for use in an ASP.NET API

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0 0 11/23/2026
4.4.7 121 11/11/2026
4.4.6 189 10/29/2026
4.4.5 115 10/27/2026
4.4.4 127 10/22/2026
4.4.3 139 10/15/2026
4.4.2 128 10/10/2026
4.4.1 110 10/10/2026
4.4.0 113 10/9/2026
4.3.7 249 9/15/2026
4.3.6 166 9/1/2026
4.3.5 164 8/27/2026
4.3.4 153 8/24/2026
4.3.3 151 8/14/2026
4.3.1 146 8/11/2026
4.3.0 169 8/3/2026
4.1.14 127 8/3/2026
4.1.12 150 7/31/2026
4.1.11 189 7/9/2026
4.1.0 267 6/5/2026
Loading failed