Skip to content
Simone Bembi edited this page Jan 30, 2018 · 3 revisions

Map

The map is the class that lets you define how the object should be mapped, specifying which properties should be mapped and how.

Property definitions can be declared after calling createMap.

e.g.

mapper.createMap<Source, Destination>(sourceDestinationSignature, Destination)
    .forMember('a', opt =>
        opt.mapFrom(source => source.aaaa)
            .immutably()
    );

The available methods are:

  • withConfiguration(mapConfiguration: TMapConfigurationSetter<S, D>) refer to Map configuration
  • forMember(selector: keyof Destination, operation: TOperationConfigurationSetter<S, D>)
    refer to Operation configuration
  • forSourceMember(selector: keyof Source, operation: TSourceOperationConfigurationSetter)
    refer to Operation configuration - Source operation
  • map(source: S | Array<S>, destination?: D | Array<D>) => D | Array<D>

Configuration

e.g.

mapper.createMap<Source, Destination>(signature, Destination)
    .withConfiguration(conf => conf
        .withPreconditions((source, destination) => destination.a === undefined)
    );

This method lets you define a configuration that will be valid for the entire map.
The allowed configuration methods are the same in the mapper configuration plus the preconditions ones.


Member

Set the operations needed to map the property from source to destination.

e.g.

mapper.createMap<Source, Destination>(signature, Destination)
    .forMember('a', operation => operation
        .mapFrom(source => source.a)
        .withPrecondition(() => operation.destination.a === undefined)
        .immutably()
    );

Further information about the operation configuration can be found on the Operation configuration documentation page.


Source member

Set the operations referred by a source property.

Further information about the source operation configuration can be found on the Operation configuration documentation page.


Map

The map methods lets you call the map without specifying the signature, because the map is specific to those Source and Destination classes.