我创建了一个IDictionary
扩展来将IDictionary Exception.Data
值写入字符串。
扩展代码:
public static class DictionaryExtension
{
public static string ToString<TKey, TValue>(this IDictionary<TKey, TValue> source, string keyValueSeparator, string sequenceSeparator)
{
if (source == null)
throw new ArgumentException("Parameter source can not be null.");
return source.Aggregate(new StringBuilder(), (sb, x) => sb.Append(x.Key + keyValueSeparator + x.Value + sequenceSeparator), sb => sb.ToString(0, sb.Length - 1));
}
}
当我使用此扩展程序时Exception.Data.ToString("=", "|")
出现错误
The type arguments cannot be inferred from the usage.
知道如何解决这个问题吗?