Question: Nullable Immutable Arrays
See original GitHub issueFirst off, amazing project. 😃 We are using it for ExtendedXmlSerializer.
Secondly, finally ran into my first problem here after many (many!) times of “just working”.
I have the following class:
class Subject
{
public Subject(ImmutableArray<int>? test)
{
Test = test;
}
public ImmutableArray<int>? Test { get; }
}
But when I do this:
new Subject(ImmutableArray.Create(1, 2, 3))
.ShouldBeEquivalentTo(new Subject(ImmutableArray.Create(1, 2, 3)));
I get the following failure: Expected member Test to be {1, 2, 3}, but found {1, 2, 3}.
Looks like it has to do with being a nullable value type. If I make it non-nullable it works as expected. Any suggestions on what I could be doing wrong? Thank you in advance for any assistance!
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Type inference for generic method differs between nullable ...
I have been warned that the immutable array is boxed when used as an enumerable, which comes with a performance penalty. But I...
Read more >Mutable and Immutable Arrays - Learn TypeScript
Mutable and Immutable Arrays. In this lesson, you will learn about two different syntaxes to define an array. We'll cover the following.
Read more >Solved True or false? All elements of an array must be of
Question : True or false? All elements of an array must be of the same type. Strings are immutable. Arrays cannot contain string...
Read more >Null safety | Kotlin Documentation
Kotlin's type system is aimed at eliminating the danger of null references, also known as The Billion Dollar Mistake.
Read more >Member access operators and expressions
C# operators that you use to access type members or null-conditionally access type members. These operators include the dot operator - `.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Source: http://www.continuousimprover.com/2018/02/fluent-assertions-50-best-unit-test.html
I found the problem. Nullable properties referring to types implementing
IEnumerable
are not detected as such, after which FA will fall back on value semantics. AndImmutableArray
implementsEquals
by comparing the underlying arrays by reference.