This post is machine-translated. The original post in german language can be found here.

Merge two maps into one

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;
}
These post applies to following version:
Dynamics AX 2012

 
 

 

 
 
 
Posts of the actual month
November 2024
MoTuWeThFrSaSu
 123
45678910
11121314151617
18192021222324
252627282930 
 
© 2006-2024 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.