Skip to content

panoramicdata/PanoramicData.Mapper

Repository files navigation

PanoramicData.Mapper

A comprehensive, MIT-licensed, API-compatible replacement for AutoMapper.

Nuget Nuget License Codacy Badge

Overview

PanoramicData.Mapper is a comprehensive, API-compatible replacement for AutoMapper with convention-based object mapping, explicit member configuration, and advanced features including mapping inheritance, value resolvers, type converters, open generics, EF Core projection, and more. It is a clean-room, black-box reimplementation — no AutoMapper source code was referenced.

Supported Features

  • Convention-based mapping — properties with matching names and compatible types map automatically
  • Profile-based configuration — derive from Profile and call CreateMap<TSource, TDestination>()
  • ForMember / Ignore — skip specific destination properties
  • ForMember / MapFrom — custom source expressions including nested property access
  • BeforeMap / AfterMap — inline lambda and generic IMappingAction<TSrc, TDest> pre/post-mapping callbacks
  • ForAllMembers — apply configuration to all destination members
  • ReverseMap.ReverseMap() creates the inverse mapping automatically
  • ConvertUsing — lambda, ITypeConverter<TSrc, TDst> type, or instance for full-type conversion
  • ConstructUsing — custom destination construction via lambda
  • ForPath.ForPath(d => d.Inner.Prop, opt => ...) for deep nested member configuration
  • ForCtorParam.ForCtorParam("name", opt => ...) for constructor parameter mapping
  • Condition / PreCondition — conditional member mapping (evaluated after/before value resolution)
  • NullSubstitute — substitute a default value when the source resolves to null
  • Value ResolversIValueResolver<TSrc, TDst, TMember> for custom resolution logic
  • Mapping InheritanceInclude, IncludeBase, IncludeAllDerived for polymorphic hierarchies
  • Value Transformers.AddTransform<T>(expr) for per-type value transforms
  • Open GenericsCreateMap(typeof(Source<>), typeof(Dest<>)) for generic type mappings
  • UseDestinationValue — preserve existing destination property values
  • MaxDepth.MaxDepth(n) to limit recursive mapping depth
  • Map to newmapper.Map<TDest>(source) creates a new destination
  • Map to existingmapper.Map(source, destination) updates an existing object
  • ProjectToIQueryable<T>.ProjectTo<TDest>(configurationProvider) for EF Core SQL projection
  • [Ignore] attributePanoramicData.Mapper.Configuration.Annotations.IgnoreAttribute
  • Nested mappings — recursive mapping of complex child types and collection properties when a CreateMap exists for the child types
  • Collection/List/Array mappingmapper.Map<List<Dest>>(sourceList) maps collections automatically when an element-type map is registered
  • Flattening — PascalCase destination property names are split and traversed on the source graph (e.g. CustomerNameCustomer.Name); also matches GetX() methods
  • AssertConfigurationIsValid — detects unmapped destination properties at startup
  • IgnoreAllPropertiesWithAnInaccessibleSetter — extension method to ignore all destination properties with non-public or absent setters
  • DI integrationAddAutoMapper() extension methods for IServiceCollection

Installation

dotnet add package PanoramicData.Mapper

Quick Start

using PanoramicData.Mapper;

// Define a profile
public class MyProfile : Profile
{
    public MyProfile()
    {
        CreateMap<Source, Destination>()
            .ForMember(d => d.Secret, opt => opt.Ignore())
            .ForMember(d => d.FullName, opt => opt.MapFrom(s => s.FirstName + " " + s.LastName));
    }
}

// Configure and use
var config = new MapperConfiguration(cfg => cfg.AddProfile<MyProfile>());
config.AssertConfigurationIsValid();

IMapper mapper = config.CreateMapper();
var dest = mapper.Map<Destination>(source);

DI Registration

// In Program.cs / Startup.cs
services.AddAutoMapper(typeof(MyProfile).Assembly);

// Or with explicit configuration
services.AddAutoMapper(cfg => cfg.AddProfile<MyProfile>());

Migration from AutoMapper

  1. Replace the AutoMapper NuGet package with PanoramicData.Mapper
  2. Update using directives:
    • using AutoMapper;using PanoramicData.Mapper;
    • using AutoMapper.QueryableExtensions;using PanoramicData.Mapper.QueryableExtensions;
    • using AutoMapper.Configuration.Annotations;using PanoramicData.Mapper.Configuration.Annotations;
  3. The AddAutoMapper() DI extension methods and all type names (Profile, IMapper, MapperConfiguration, etc.) remain the same

License

MIT — see LICENSE for details.

About

A minimal, API-compatible replacement for AutoMapper. Supports convention-based mapping, ForMember, Ignore, MapFrom, AfterMap, ProjectTo, and DI integration.

Resources

License

Stars

Watchers

Forks

Packages