Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Add convenience and nullable safe method. #13205

Merged
merged 1 commit into from
Feb 8, 2023

Commits on Feb 8, 2023

  1. [Windows] Add convenience and nullable safe method.

    During the code reviews I have noticed several occurrences of the of the
    following pattern:
    
    ```csharp
    if (nativeSlider.GetFirstDescendant<Thumb>() is Thumb thumb)
    {
      thumb.Height = defaultThumbSize.Value.Height;
      thumb.Width = defaultThumbSize.Value.Width;
    }
    ```
    
    The above works, but it is abussing the is operator and is making us
    type more than is really needed (several ocurrences of the type). The
    given method will be used as follows:
    
    ```csharp
    if (nativeSlider.TryGetFirstDescendant<Thumb>(out var thumb))
    {
      thumb.Height = defaultThumbSize.Value.Height;
      thumb.Width = defaultThumbSize.Value.Width;
    }
    ```
    or
    ```csharp
    if (nativeSlider.TryGetFirstDescendant(out Thumb? thumb))
    {
      thumb.Height = defaultThumbSize.Value.Height;
      thumb.Width = defaultThumbSize.Value.Width;
    }
    ```
    Nullability is not needed thansk to the NotNullWhenAttribute.
    mandel-macaque committed Feb 8, 2023
    Configuration menu
    Copy the full SHA
    74b860e View commit details
    Browse the repository at this point in the history