Map.pack Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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();
}