-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the bug
There are a number of inconsistencies in the various extensions in the LogicalTree and VisualTree extensions. Specifically, in the way input arguments are validated and used to perform the various requested operations. For instance:
If element is null, the method will gracefully bail and return null.
If element is null, the method will throw a NullReferenceException on line 237.
Similarly, the former will match the name with the input element as a first step, and then navigate upwards, whereas the second one will not check the input element at all and only look for matches in the visual hierarchy. I'd argue the latter is more correct and appropriate for the name of the method, but regardless, the behavior should be consistent.
There are a number of similar issues in the two classes, plus some optimizations that could be done while we're at it (namely, to manually unroll some recursive tail calls, since the C# compiler doesn't support the .tail opcode automatically).
cc. @michael-hawker If I'm not mistaking, these would be the ones you asked me about a while back too? 🤔
Also, I think we should agree on a standard handling of arguments in order for them to be properly annotated.
Personally I would suggest:
- Marking input arguments as non-nullable reference types, and use the implicit NRE if they're
null - Marking the returned value as nullable, ie.
FrameworkElement?
I can help with this and make a PR when we agree on how to approach these various points.
The changes would go into 7.0 anyway, so I think it would be ok for us to make breaking changes 😊
Package Version(s): Microsoft.Toolkit.Uwp.UI 6.1.1, from master