public static ConvertToString ( object>.IDictionary | ||
dictionary | object>.IDictionary | The dictionary. |
separator | string | The separator to separate key value pairs. |
return | string |
public static string ConvertToString(IDictionary<object, object> dictionary, string separator)
{
Ensure.ArgumentNotNull(separator, "seperator");
StringBuilder sb = new StringBuilder();
if (dictionary != null)
{
foreach (KeyValuePair<object, object> valuePair in dictionary)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}={1}{2}", valuePair.Key, valuePair.Value, separator);
}
// cut away last separator
if (sb.Length > 0)
{
sb.Length -= separator.Length;
}
}
return sb.ToString();
}
}
FormatHelper::ConvertToString ( IEnumerable collection, string separator ) : string |
public void ConvertDictionaryToString() { IDictionary <object, object> dictionary = new Dictionary <object, object>(); dictionary.Add("bla", "haha"); dictionary.Add(1, 25); dictionary.Add("exception", new Exception("exception")); string s = FormatHelper.ConvertToString(dictionary, "; "); s.Should().Be("bla=haha; 1=25; exception=System.Exception: exception"); }