//The MIT License (MIT)
//http://arolibraries.codeplex.com/license
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
namespace AroLibraries.ExtensionMethods.Enumerable
{
public static class ArrayExt
{
public static Size Ext_GetSize(this Array iArray)
{
Size vSize = new Size();
int length = iArray.Length;
int rank = iArray.Rank;
int[] index = null;
if (rank == 1)
{
vSize.Height = 0;
vSize.Width = length;
}
else if (rank == 2)
{
index = new int[2];
for (int i = 0; i <= length; i++)
{
index[0] = i;
try
{
iArray.GetValue(index);
}
catch (Exception)
{
vSize.Width = i;
break;
}
}
index[0] = 0;
for (int i = 0; i <= length; i++)
{
index[1] = i;
try
{
iArray.GetValue(index);
}
catch (Exception)
{
vSize.Height = i;
break;
}
}
}
return vSize;
}
}
}
|