map method
MappingDefinition<S, T>
map({
- dynamic constant,
- dynamic from,
- PropertyQualifier? all,
- dynamic to,
- bool deep = false,
- bool validate = false,
- Convert? convert,
specifies a single operation, that will be executed while mapping.
constant
maps a constant value as a source
from
either a single source field or a field path
to
either a single target field or a field path
all
a PropertyQualifier wild card, that is used instead of from and to
deep
if true
, a different supplied mapping is expected to transform the retrieved source value recursively
convert
optional Convert instance
Implementation
MappingDefinition<S,T> map({dynamic constant, dynamic from, PropertyQualifier? all, dynamic to, bool deep = false, bool validate = false, Convert? convert}) {
if ( all != null) {
operations.add(MapProperties(qualifier: all, converter: convert, deep: deep));
}
else {
List<Accessor> fromAccessors = [];
List<Accessor> toAccessors = [];
if ( from is Accessor)
fromAccessors.add(from);
if ( from is String)
fromAccessors.add(PropertyAccessor(name: from));
else if (from is List<String>)
fromAccessors = (from).map((element) => PropertyAccessor(name: element)).toList(growable: false);
if ( constant != null)
fromAccessors.add(ConstantAccessor(value: constant));
if ( to is Accessor)
toAccessors.add(to);
if ( to is String)
toAccessors.add(PropertyAccessor(name: to, validate: validate));
if (to is List<String>)
toAccessors = (to).map((element) => PropertyAccessor(name: element)).toList(growable: false);
// done
operations.add(MapAccessor(
source: fromAccessors,
target: toAccessors,
deep: deep,
converter: convert
));
}
return this;
}