Hi there,
writing some code to test my own stuff I stumbled about the MigraDoc.DocumentObjectModel.Borders object.
This short test method will throw a System.InvalidCastException:
Code:
[TestMethod]
public void TestForMigraDocBugReport()
{
var paragraphFormat = new ParagraphFormat();
foreach (var border in paragraphFormat.Borders)
{
Trace.WriteLine(border.ToString()); // or whatever
}
}
It will fail because the Borders.BorderEnumerator is using a Dictionary<string, Border> and when finally enumerating about its contents, it casts the enumerator.Current entry to a DictionaryEntry object, what will throw the InvalidCastException. This is simply because the .net Dictionary<TKey, TValue> class is implementing the IEnumerable<KeyValuePair<TKey,TValue>> interface rather than IEnumerable<DictionaryEntry<TKey,TValue>>.
Suggested code change
Code:
public Border Current
{
get
{
IEnumerator enumerator = _ht.GetEnumerator();
enumerator.Reset();
for (int i = 0; i < _index + 1; i++)
{
enumerator.MoveNext();
}
/* remove return ((DictionaryEntry)enumerator.Current).Value as Border; */
/* instead : */
return ((KeyValuePair<string, Border>)enumerator.Current).Value as Border;
}
}