set aTargetObject = anInputObject.mapEqualNames([anotherInputObject]+);
append mapEqualNames(anInputObject) to anArrayOfTargetObjects;
Semantics
The macro generates set statements for all equal named, equally typed attributes found in the target object and at least one of the input objects. This applies to all public attributes including all inherited attributes.
You can supply multiple input objects.
This macro does not work recursively and thus do not perform a deep copy of attributes of complex types.
Substitutables
anInputObject, anotherInputObject
Can be any complex object having attributes of any type.
Examples
set person = person1.mapEqualNames(person2, person3);
set person.address = mapEqualNames(address);
set person.alternativeAddress = detailedPerson.address.mapEqualNames();
set person.adress = mapEqualNames(detailedPerson.addresses[0]);
append mapEqualNames(detailedPerson) to people;
Usage of mapEqualNames()
Given are the two unrelated classes Person and DetailedPerson.
The properties of personIn1 get overwritten with existing values. The value of streetremains unchanged, because it did not exist in the source object personIn2(was NULL).
Usage of mapEqualNames() with the "append" Statement
You can use mapEqualNames() along with the append statement to add a complex object with numerous attributes to an array of unrelated objects which needs only some of the information. The mapEqualNames()macro will create set statements for all equal named attributes found in the target object while the append statement will add the result to an array.
Given are the two unrelated classesPerson and DetailedPerson.
Assume that aDetailedPerson is provided from an external source. For further processing, we are interested in nameand surnameonly.
append mapEqualNames(aDetailedPerson) to customers;
mapEqualNames() collects the data from aDetailedPerson, and append adds it to the array customers. customers is an array of typePersonand contains already the data of "John Snow" and "Liv Falls".