Skip to content

Collection `ToString` and various fixes

Compare
Choose a tag to compare
@louthy louthy released this 12 Jan 14:03

Collections ToString

All of the collection types now have a default ToString() implementation for small list-like collections:

    "[1, 2, 3, 4, 5]"

And for maps: (HashMap and Map):

    "[(A: 1), (B: 2), (C: 3), (D: 4), (E: 5)]"

Larger collections will have CollectionFormat.MaxShortItems and then an ellipsis followed by the number of items remaining. Unless the collection is lazy, in which case only the ellipsis will be shown:

    "[1, 2, 3, 4, 5 ... 50 more]"

CollectionFormat.MaxShortItems can be set directly if the default of 50 items in a ToString() isn't suitable for your application.

In addition to this there's two extra methods per collection type:

    string ToFullString(string separator = ", ")

This will build a string from all of the items in the collection.

    string ToFullArrayString(string separator = ", ")

This will build a string from all of the items in the collection and wrap with brackets [ ].

Fixes