Replies: 2 comments
-
Can the element type of New items be null? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think this is because nullability is remembered for simple property access, treating properties like variables, it's not remembered for indexers. Similarly, it's not remembered for method calls. Here's how I would prefer to write the assertion: Debug.Assert(!(eventArgs.NewItems is { Count: > 0 } && eventArgs.NewItems[0] is { } first && first.GetType() != typeof(TEntity)));
// Or
Debug.Assert(!(eventArgs.NewItems?.Cast<object>().FirstOrDefault() is { } first && first.GetType() != typeof(TEntity))); If the comparison should be Debug.Assert(eventArgs.NewItems?.Cast<object>().FirstOrDefault() is null or TEntity); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Just taking C# 9 for a spin and found this --
Expected: no warnings
Actual: "Dereference of a possibly null reference" in the expression "eventArgs.NewItems[0].GetType()".
It seems to think that eventArgs.NewItems[0] could be null even though that possibility was just tested in the preceding OR clause. Weirdly, this happens on eventArgs.NewItems[0].GetType() but not on eventArgs.NewItems.Count.
Beta Was this translation helpful? Give feedback.
All reactions