Enable nullability in Link class#7992
Conversation
| Region region = _owningLink.VisualRegion; | ||
| using Graphics graphics = Graphics.FromHwnd(_owningLink.Owner.Handle); | ||
| Region? region = _owningLink.VisualRegion; | ||
| using Graphics graphics = Graphics.FromHwnd(_owningLink.Owner?.Handle ?? IntPtr.Zero); |
There was a problem hiding this comment.
Are you forced to pass IntPtr.Zero here?
There was a problem hiding this comment.
Yes, if Owner is null (which it can be) then we have no handle.
I would, however, move the check up to line:31 - if we don't have a valid handle, then we create Graphics object for the desktop area, which feels wrong. In this case it probably better to return an empty rectangle.
@Tanya-Solyanik @dmitrii-drobotov what do you think?
There was a problem hiding this comment.
I know owner can be null. I mean, is null not accepted for this call? what is forcing to explicit pass of IntPtr.Zero?
There was a problem hiding this comment.
I'm not sure I understand your questions... Please help me.
IntPtr is a struct, Graphics.FromHwnd(IntPtr) doesn't accept null.
There was a problem hiding this comment.
my mistake. i thought that method is accepting null.
There was a problem hiding this comment.
Yes, if
Owneris null (which it can be) then we have no handle. I would, however, move the check up to line:31 - if we don't have a valid handle, then we createGraphicsobject for the desktop area, which feels wrong. In this case it probably better to return an empty rectangle.@Tanya-Solyanik @dmitrii-drobotov what do you think?
I agree that returning an empty rectangle is better in this case. But this is probably an extremely rare scenario since _owningLink.Owner should be the same object as _owningLinkLabel:
RussKie
left a comment
There was a problem hiding this comment.
👍 modulo the discussion in LAO.
|
Thank you |
Proposed changes
Microsoft Reviewers: Open in CodeFlow