🧙‍♂️
Dynamic Mapper
  • DynamicMapper
  • Getting started
  • Configuration
    • Member configuration
    • Subtyping
  • Profiles
  • Integrations
    • Angular
Powered by GitBook
On this page
  • mapFrom
  • mapFromUsing
  • addTransform
  • condition
  • preCondition
  • nullSubstitute
  • ignore
  • auto

Was this helpful?

  1. Configuration

Member configuration

mapFrom

Sets function that takes in source object and returns destination value.

createMap(SrcToDst, {
    bar: opt => opt.mapFrom(src => src.foo)
});

mapFromUsing

Similarly to mapFrom takes in mapping function and MappingPair which configuration will be used to map corresponding member.

createMap(SrcToDst, {
    bar: opt => opt.mapFromUsing(src => src.foo, FooToBar)
});

addTransform

Transforms value before mapping to destination.

createMap(SrcToDst, {
    bar: opt => {
        opt.mapFrom(src => src.foo);
        opt.addTransform(dest => dest + ', it was mapped!');
    }
});

condition

Called before destination value will be assigned.

createMap(SrcToDst, {
    bar: opt => {
        opt.condition(src => src.foo != null);
        opt.mapFrom(src => src.foo);
    }
});

preCondition

Called before resolving destination value and stops mapping on false.

createMap(SrcToDst, {
    bar: opt => {
        opt.preCondition(src => src.foo != null);
        opt.mapFrom(src => {
            // expensive resolution avoided with preCondition
        });
    }
});

nullSubstitute

When source member value resolves to null or undefined alternate value will be used.

createMap(SrcToDst, {
    bar: opt => {
        opt.nullSubstitute(123);
        opt.mapFrom(src => src.foo);
    }
});

ignore

Skips this member during mapping.

createMap(SrcToDst, {
    bar: opt => opt.ignore()
});

auto

Explicitly marks member for auto mapping. Can be called only on members present on both source and destination.

createMap(SrcToDst, {
    bar: opt => opt.auto()
});
PreviousConfigurationNextSubtyping

Last updated 5 years ago

Was this helpful?