Appccelerate.Formatters.FormatHelper.ConvertToString C# (CSharp) Method

ConvertToString() public static method

Converts a dictionary of object, object to a string representation in the form of Key=Valueseparator.
public static ConvertToString ( object>.IDictionary dictionary, string separator ) : string
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();
        }
    }

Same methods

FormatHelper::ConvertToString ( IEnumerable collection, string separator ) : string

Usage Example

Example #1
0
        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");
        }
All Usage Examples Of Appccelerate.Formatters.FormatHelper::ConvertToString