public void TestToString() { var set = new HashSet <IDictionary <string, string> > { new Dictionary <string, string> { { "1", "one" }, { "2", "two" }, { "3", "three" } }, new Dictionary <string, string> { { "4", "four" }, { "5", "five" }, { "6", "six" } }, new Dictionary <string, string> { { "7", "seven" }, { "8", "eight" }, { "9", "nine" } }, }; var setExpected = "[{1=one, 2=two, 3=three}, {4=four, 5=five, 6=six}, {7=seven, 8=eight, 9=nine}]"; Assert.AreEqual(setExpected, Collections.ToString(set)); var map = new Dictionary <string, IDictionary <int, double> > { { "first", new Dictionary <int, double> { { 1, 1.23 }, { 2, 2.23 }, { 3, 3.23 } } }, { "second", new Dictionary <int, double> { { 4, 1.24 }, { 5, 2.24 }, { 6, 3.24 } } }, { "third", new Dictionary <int, double> { { 7, 1.25 }, { 8, 2.25 }, { 9, 3.25 } } }, }; var mapExpectedPortuguese = "{first={1=1,23, 2=2,23, 3=3,23}, second={4=1,24, 5=2,24, 6=3,24}, third={7=1,25, 8=2,25, 9=3,25}}"; var mapExpectedUSEnglish = "{first={1=1.23, 2=2.23, 3=3.23}, second={4=1.24, 5=2.24, 6=3.24}, third={7=1.25, 8=2.25, 9=3.25}}"; Assert.AreEqual(mapExpectedPortuguese, Collections.ToString(map, new CultureInfo("pt"))); Assert.AreEqual(mapExpectedUSEnglish, Collections.ToString(map, new CultureInfo("en-US"))); var array = new List <Dictionary <string, string> >[] { new List <Dictionary <string, string> > { new Dictionary <string, string> { { "foo", "bar" }, { "foobar", "barfoo" } } }, new List <Dictionary <string, string> > { new Dictionary <string, string> { { "orange", "yellow" }, { "red", "black" } }, new Dictionary <string, string> { { "rain", "snow" }, { "sleet", "sunshine" } } }, }; var arrayExpected = "[[{foo=bar, foobar=barfoo}], [{orange=yellow, red=black}, {rain=snow, sleet=sunshine}]]"; Assert.AreEqual(arrayExpected, Collections.ToString(array)); }
/// <summary> /// Returns a string representation of this collection (and any nested collections). /// The string representation consists of a list of the collection's elements in /// the order they are returned by its enumerator, enclosed in square brackets /// ("[]"). Adjacent elements are separated by the characters ", " (comma and space). /// </summary> /// <returns>a string representation of this collection</returns> public override string ToString() { return(Collections.ToString(this)); }