I'm currently writing an interface to allow applications to send exception data to a central repository for support purposes. I'm at a quandary about how to pass extra contextual data:
public interface IExceptionNotifier
{
void Notify(Exception ex, NameValueCollection context); //this
void Notify(Exception ex, IDictionary<string, string> context); //or this
}
I've often found myself is a similar position when creating lookups. Ignoring whether or not the exception notifier concept is good, is it be best to use an IDictionary<string, string>
or NameValueCollection
? Why would you pick one over the other?
(Assuming .NET 3.5 here. Pre .NET 3.5, NameValueCollection would have the benefit of being able to tie multiple values to a key, with no direct equivalent in "normal" collections.)
Do you want keys to have potentially multiple values? If so, I'd consider ILookup<TKey, TValue>. Otherwise, I'd go for IDictionary<TKey, TValue>.
Aside from anything else, if the receiver wants to do any processing where LINQ would be of use to them, either of the generic interfaces is going to be nicer than NameValuePair. Likewise, it may be easier for the caller to produce a dictionary/lookup using LINQ if they've already got a generic or dynamic kind of context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With