public static CBORObject FromArray(
Object arrObj,
PODOptions options)
{
var arr = (Array)arrObj;
int rank = arr.Rank;
if (rank == 0)
{
return(CBORObject.NewArray());
}
CBORObject obj = null;
if (rank == 1)
{
// Most common case: the array is one-dimensional
obj = CBORObject.NewArray();
int len = arr.GetLength(0);
for (var i = 0; i < len; ++i)
{
obj.Add(
CBORObject.FromObject(
arr.GetValue(i),
options));
}
return(obj);
}
var index = new int[rank];
var dimensions = new int[rank];
for (var i = 0; i < rank; ++i)
{
dimensions[i] = arr.GetLength(i);
}
if (!FirstElement(index, dimensions))
{
return(obj);
}
obj = BuildCBORArray(dimensions);
do
{
CBORObject o = CBORObject.FromObject(
arr.GetValue(index),
options);
SetCBORObject(obj, index, o);
} while (NextElement(index, dimensions));
return(obj);
}