Compartir a través de


Map.pack Method

Definition

Serializes the current instance of the Map class.

public:
 cli::array <System::Object ^> ^ pack();
public object[] pack ();
member this.pack : unit -> obj[]
Public Function pack () As Object()

Returns

Object[]

A container that contains the current instance of the Map class.

Remarks

The container created by this method contains 4 elements before the first element from the map:

  • A version number for the container
  • An integer that identifies the data type of the keys in the map
  • An integer that identifies the data type of the values in the map
  • The number of elements in the map

If the keys or the values are objects, packing is performed by calling the pack method successively on each object to yield a subcontainer. The pack and unpack methods cannot preserve X++ anytype values. One option is to put the anytype values into objects or structs, and have the structs be the values in the Map object. Use of Microsoft .NET System.Collections classes is another option. The map can be retrieved from the packed container by using the Map.create method.

The following example creates a map from a container that is passed into the method (conprojItemTransSalesAmount), adds some values to it, and then uses MapEnumerator.pack to pack the map into a container. The new container is then returned by the method.

server static container salesAmountDisplayCache( 
    container   _conprojItemTrans, 
    container   _conprojItemTransSalesAmount, 
    TransDate   _ledgerFromDate, 
    TransDate   _ledgerToDate) 
{ 
    ProjItemTrans    projItemTrans; 
    Set              setprojItemTrans; 
    Map              mapprojItemTransSalesAmount; 
    SetIterator      si; 
    if(_conprojItemTrans) 
    { 
        setprojItemTrans = Set::create(_conprojItemTrans); 
    } 
    if(_conprojItemTransSalesAmount) 
    { 
        mapprojItemTransSalesAmount = Map::create( 
            _conprojItemTransSalesAmount); 
    } 
    si = new SetIterator(setprojItemTrans); 
    si.begin(); 
    while (si.more()) 
    { 
        projItemTrans = ProjItemTrans::find(si.value()); 
        mapprojItemTransSalesAmount.insert( 
            si.value(),  
            projItemTrans.salesAmount( 
                projItemTrans, 
               _ledgerFromDate, 
               _ledgerToDate)); 
        si.next(); 
    } 
    return mapprojItemTransSalesAmount.pack(); 
}

Applies to