protected void AddCoordinates(SortedDictionary<string, object> dict, string key, object coordObj)
{
if (coordObj == null) return;
if (coordObj is Rectangle)
{
var rect = (Rectangle)coordObj;
dict.Add(key, string.Format("{0},{1},{2},{3}", rect.X, rect.Y, rect.Width, rect.Height));
}
else if (coordObj is List<Rectangle>)
{
var list = (List<Rectangle>)coordObj;
dict.Add(key, string.Join("|", list.Select(r => string.Format("{0},{1},{2},{3}", r.X, r.Y, r.Width, r.Height)).ToArray()));
}
else
{
dict.Add(key, coordObj.ToString());
}
}