Nullability in Microsoft.Maui.Controls
#30788
Unanswered
cleardemon
asked this question in
General
Replies: 1 comment
-
There are PRs that improve the status quo:
This would be a nice community PR to target the
There is #12600. But yes, it's a lot of work. However, one can slowly improve it. |
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Using nullability support in modern C# is pretty common, however, there seems to be plenty of occurrences where, in MAUI, nullability is simply not supported.
An example is when using
Shell.Current
, while unlikely (but still possible, given a recent crash on Android in production), this property can actually returnnull
.Drilling down, Shell.Current is a wrapper for
Application.Current
. ButShell.Current
is not declared as possibly returningnull
, in fact, in theShell.cs
file,#nullable disable
is right at the top.It's not just this. There are other places where things can be null in MAUI, and they are just not declared as being so in the API. When using nullable throughout one's project, this does not provide the benefit of being able to spot when properties can be null, potentially leading to unchecked null references.
Obviously, you can still check if a property is null. But, with
#nullable enable
, if you check a property likeInputView.Text
- which does not declare itself as nullable, either, despite saying it defaults tonull
in the documentation - you get a warning sayingText
can't be null.Is there a plan to support nullability properly in MAUI? It seems patchy (e.g.
Application.Current
is nullable), and it seems like there is room for improvement, but it also seems like a rather large task to do.Beta Was this translation helpful? Give feedback.
All reactions