Skip to content

Create map for member: ignore

Bert Loedeman edited this page Aug 26, 2015 · 2 revisions

Ignore destination properties

It is possible to ignore destination properties while mapping using the createMap.forMember.ignore function.

// arrange
var objA = { prop: 1 };

var fromKey = '{76D26B33-888A-4DF7-ABDA-E5B99E944272}';
var toKey = '{18192391-85FF-4729-9A08-5954FCFE3954}';

automapper
	.createMap(fromKey, toKey)
	.forMember('prop', (opts: AutoMapperJs.IMemberConfigurationOptions) => { opts.ignore(); });

// act
var objB = automapper.map(fromKey, toKey, objA);

// assert
expect(objB.hasOwnProperty('prop')).not.toBeTruthy();

Tip: it is also possible to get ignorance to work based on a condition.