I have a method I am not happy with, can you please show me how to do this better.
public Foo WithBar(IDictionary<string, object> parameters) {
var strStrDict = new Dictionary<string, string>(parameters.Count);
foreach(var pair in parameters)
{
strStrDict.Add(pair.Key, pair.Value != null ? pair.Value.ToString() : (string)null);
}
// Call overload which takes IDictionary<string, string>
return this.WithBar(strStrDict);
}
This code works but I’m sure there is a nice linq’y way of doing this I am missing.
1 Answer