-
Notifications
You must be signed in to change notification settings - Fork 36
Conditional mapping
Bert Loedeman edited this page Aug 26, 2015
·
1 revision
AutoMapper allows you to add conditions to properties that must be met before that property will be mapped.
This can be used in situations like only mapping numbers which have a value >= 0.
class Person {
age: number;
}
class ApiPerson {
age: number; // specified as -1 when empty in db
}In the following mapping the property age will only be mapped if it is greater than or equal to 0 in the source object.
automapper.createMap('ApiPerson', 'Person')
.forMember('age', (opts: AutoMapperJs.IMemberConfigurationOptions) => {
opts.condition((sourceObject: any) =>
sourceObject.age >= 0)
}
);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