This post is machine-translated. The original post in german language can be found here.
These post applies to following version:
Dynamics AX 2012
Dynamics AX 2012
|
|
|
|
|
|
|
This post is machine-translated. The original post in german language can be found here.
These post applies to following version:
Dynamics AX 2012
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Recently, I wanted to merge two maps into one, but I did not find an appropriate function, so I wrote the following myself.
private Map mergeMaps(Map _map1, Map _map2) { Map retMap; MapEnumerator mapEnum; // Initate first map from second map if empty if( !_map1) { _map1 = new Map(_map2.keyType(), _map2.valueType()); } // Check compatibility if(_map1 && _map2) { if(_map1.keyType() != _map2.keyType() || _map1.valueType() != _map2.valueType()) { throw error(Error::wrongUseOfFunction(funcName())); } } retMap = _map1; mapEnum = _map2.getEnumerator(); while(mapEnum.moveNext()) { if( !retMap.exists(mapEnum.currentKey())) { retMap.insert(mapEnum.currentKey(), mapEnum.currentValue()); } } return retMap; }