I have written an extension method to help with collecting crash data during error reporting. This method is designed to ensure that a key is always unique. If you have a few try/catch blocks, sometimes data can get duplicated. I'm going for reasonably easy here, not super-best practices.
The problem: changing the key if it isn't unique. When I try the below, method, I get "cannot convert from 'string' to 'TKey'". Any ideas?
public static void AddUnique<TKey, TValue>(this System.Collections.IDictionary dictionary, TKey key, TValue value)
{
if(dictionary[key] != null)
{
var newKey = key.ToString() + "-";
AddUnique<TKey, TValue>(dictionary, newKey, value);
}
...
}