-
Notifications
You must be signed in to change notification settings - Fork 36
create map for member
The createMap.forMember function specifies what action has to be performed when mapping a certain destination member.
Multiple forMember function calls can be chained together. In most cases, there will be one forMember function call for each destination member; however, it is possible to chain multiple forMember function calls for one destination member. The actions specified will be performed in a top-to-bottom manner, while the intermediate result is stored and passed through in the options object. unless you specify opts.ignore() or opts.mapFrom(), which will already be executed at configuration time.
createMap.forMember function sample to always return a constant value.
var constantResult = 2;
automapper
.createMap(fromKey, toKey)
.forMember('prop', constantResult);
createMap.forMember function sample to always return a constant value using a function.
var constantResult = 3;
automapper
.createMap(fromKey, toKey)
.forMember('prop', () => { return constantResult });
createMap.forMember function sample to return a value calculated using the source object and property name.
automapper
.createMap(fromKey, toKey)
.forMember('prop', (opts: AutoMapperJs.IMemberConfigurationOptions) => { return opts.sourceObject[opts.sourcePropertyName].subProp.value * 2; });
Ignore a destination property
createMap.forMember function sample to ignore a property.
automapper
.createMap(fromKey, toKey)
.forMember('prop', (opts: AutoMapperJs.IMemberConfigurationOptions) => { opts.ignore(); });
createMap.forMember function sample to map a property from another property.
automapper
.createMap(fromKey, toKey)
.forMember('prop', (opts: AutoMapperJs.IMemberConfigurationOptions) => { opts.mapFrom('propDiff'); });
createMap.forMember chained functions sample to map a property using a multi-step missile approach.
automapper
.createMap(fromKey, toKey)
.forMember('birthday', (opts: AutoMapperJs.IMemberConfigurationOptions) => { opts.mapFrom('birthdayString'); })
.forMember('birthday', (opts: AutoMapperJs.IMemberConfigurationOptions) => { return new Date(opts.destinationPropertyValue); });
AutoMapperTS is Copyright © 2015 Bert Loedeman and other contributors under the MIT license.
Getting started
Mapping performance
Initialization (initialize)
Mapping configuration (createMap)
- forMember
- forSourceMember
- condition
- forAllMembers
- ignoreAllNonExisting
- convertToType
- convertUsing
- withProfile
Validation (assertConfigurationIsValid)
Mapping (map)
Currying
Custom type converters
Profiles
Chaining
Naming conventions
Asynchronous mapping
Flattening and nesting