I was hoping to receive some criticism on this block of code. I wrote it to write the contents of a dictionary to excel range in VSTO. It works well. I am interested to see how people could improve it. What would you do differently to make it more expressive, efficient?
public static void WriteToRange(this Dictionary<string, object[]> DicToRange, excel.Range toRange)
{
object[,] storeDictionaryData = new object[DicToRange.Max(maxValues=> maxValues.Value.Length),DicToRange.Count];
int keyCounter=0;
int valueCounter =0;
foreach (var key in DicToRange.Keys)
{
if (keyCounter < storeDictionaryData.GetLength(1))
{
foreach (var value in DicToRange[key])
{
if (valueCounter < storeDictionaryData.GetLength(0))
{
storeDictionaryData[valueCounter, keyCounter] = value;
valueCounter++;
}
}
keyCounter++;
valueCounter = 0;
}
}
dynamic rangeToFill=toRange.get_Resize(storeDictionaryData.GetLength(0), storeDictionaryData.GetLength(1));
rangeToFill.Value = storeDictionaryData;
}