How about a generic solution using LINQ?
private string GetDiffTableRows<TKey, TValue>(IDictionary<TKey, TValue> oldValues, IDictionary<TKey, TValue> newValues)
{
TValue oldValue, newValue;
var diffs = oldValues.Keys.Concat(newValues.Keys).Distinct().Select(k => new
{
Key = k,
OldHasKey = oldValues.TryGetValue(k, out oldValue),
NewHasKey = newValues.TryGetValue(k, out newValue),
OldValue = oldValue,
NewValue = newValue
}).Where(d => d.OldHasKey != d.NewHasKey || !Equals(d.OldValue, d.NewValue));
var tableRows = diffs.Select(d => string.Format(DiffTableRowFormatString, d.Key, d.OldValue, d.NewValue));
return string.Join(string.Empty, tableRows);
}
private const string DiffTableRowFormatString =
"<tr style='border: 1px solid black;'>" +
"<td style='border: 1px solid black;'>{0}</td>" +
"<td style='border: 1px solid black;'>{1}</td>" +
"<td style='border: 1px solid black;'>{2}</td>" +
"</tr>";