As a result of #1, the default comparison behavior for non-string IEnumerable properties is to compare the items in the enumerable rather than use referential equality. However, this behavior does not carry over to the default ToString() implementations. If we unwrap an enumerable to for checks of equality and hash code generation, we should certainly unwrap that enumerable in the default ToString() implementation.
Task
Update the ToString() implementation on ImmutableBase<TImmutable> to create array-looking string representations of properties treated as enumerables, like so:
public class MyImmutable : ImmutableBase<MyImmutable> {
public int Number { get; }
public IEnumerable<String> EnumerableProperty { get; }
public MyImmutable(int number, IEnumerable<String> enumerableProperty) {
this.Number = number;
this.EnumerableProperty = enumerableProperty;
}
}
public class MyImmutableTests {
[Test]
public void ToStringUnwraps() {
// Arrange
var immutable = new MyImmutable(5, new [] { "biz", "buzz" });
// Act
var output = immutable.ToString();
// Assert
Assert.Equal("{ Number: 5, EnumerableProperty: [ biz, buzz ] }", output);
}
}
Background
As a result of #1, the default comparison behavior for non-string
IEnumerable
properties is to compare the items in the enumerable rather than use referential equality. However, this behavior does not carry over to the defaultToString()
implementations. If we unwrap an enumerable to for checks of equality and hash code generation, we should certainly unwrap that enumerable in the defaultToString()
implementation.Task
Update the
ToString()
implementation onImmutableBase<TImmutable>
to create array-looking string representations of properties treated as enumerables, like so: