Skip to content

Improve handling of arrays (and nested arrays) as examples #263

@matt-jenner

Description

@matt-jenner

Improve handling of arrays (and nested arrays) as examples

While looking at my other issue I noticed that handling of nested arrays is not supported very well (understandably an edge-case but I thought I'd take a further look). For example consider arrays like this:

new []{ new []{"bob",jim"}, new []{"fred","whoozit"} }

This when displayed on the report as an example will both come out as follows currently:

System.String[] , System.String[]

You just get whatever the result of the ToString method on whatever object type the object is. This effectively hides the example values from the user in the report.

My first thought was to check cach item in the array to see if it is itself an array, and if so recursively flatten it, however this would lead to misleading results however, consider these two examples:

new []{ new []{"bob",jim"}, new []{"fred","whoozit"} }
new []{ "bob", "jim", "fred", "whoozit" }

These will render identically:

bob, jim, fred, whoozit
bob, jim, fred, whoozit

This is also misleading, so I also propose wrapping arrays in an identifier (so-far I've used []'s) this way you can tell the structure of the array passed in. This is obviously not quite as clean but it is functional in showing the examples used are unique, if I used this approach the examples I've used would display as:

[[bob, jim], [fred, whoozit]]
[bob, jim, fred, whoozit]

This approach can also manage to display an object array with different arrays and non-array entries in an understandable way:

new object[]{ new []{"bob",jim"}, new []{1,2}, "thingy", 3 }

would render as:

[[bob, jim], [1, 2], thingy, 3]

I've completed an initial implementation of this locally but I thought I'd check to see whether you think this is useful to include in the product and if you have any suggestions for modifications before raising a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    need-more-infoNeeds more information or there a pending questions that need answering.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions