Skip to content

Commit 7e6f416

Browse files
author
Simeon
authored
Convert to modern null checking now that it works in .NET Native. (#427)
This is mostly a find-and-replace of the == null and != null checks. This makes the code consistent, modern, and safe from equality overloading errors. I have not replaced them in the generated code. I have made the C# generator output the "is not null" pattern.
1 parent 11c75f8 commit 7e6f416

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+204
-202
lines changed

LottieGen/MSBuildTask/LottieGen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ protected override string GenerateCommandLineCommands()
211211
AddArg(nameof(InputFile), InputFile!);
212212
AddArg(nameof(Language), Language!);
213213

214-
if (AdditionalInterface != null)
214+
if (AdditionalInterface is not null)
215215
{
216216
foreach (var value in AdditionalInterface)
217217
{
@@ -238,7 +238,7 @@ protected override string GenerateCommandLineCommands()
238238

239239
void AddOptional(string parameterName, object? value)
240240
{
241-
if (value != null)
241+
if (value is not null)
242242
{
243243
AddArg(parameterName, value.ToString());
244244
}

LottieViewer/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ protected override void OnWindowCreated(WindowCreatedEventArgs args)
8787
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
8888
{
8989
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
90-
if (titleBar != null)
90+
if (titleBar is not null)
9191
{
9292
var backgroundColor = (SolidColorBrush)Current.Resources["BackgroundBrush"];
9393
var foregroundColor = (SolidColorBrush)Current.Resources["ForegroundBrush"];
94-
var inactiveBackgroundColor = (SolidColorBrush)Current.Resources["ToolsBackgroundBrush"];
94+
9595
titleBar.ButtonBackgroundColor = backgroundColor.Color;
9696
titleBar.ButtonForegroundColor = foregroundColor.Color;
9797
titleBar.BackgroundColor = backgroundColor.Color;

LottieViewer/MainPage.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ async Task OnPickFileAsync()
157157
// Ignore PickSingleFileAsync exceptions so they don't crash the process.
158158
}
159159

160-
if (file == null)
160+
if (file is null)
161161
{
162-
// Used declined to pick anything.
162+
// User declined to pick anything.
163163
return;
164164
}
165165

LottieViewer/PaletteColorPicker.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ internal LottieVisualDiagnosticsViewModel? DiagnosticsViewModel
4747
return;
4848
}
4949

50-
if (_diagnosticsViewModel != null)
50+
if (_diagnosticsViewModel is not null)
5151
{
5252
// Unhook form the previous DiagnosticsViewModel.
5353
value.ThemePropertyBindings.CollectionChanged -= Value_CollectionChanged;
5454
}
5555

5656
_diagnosticsViewModel = value;
5757

58-
if (_diagnosticsViewModel != null)
58+
if (_diagnosticsViewModel is not null)
5959
{
6060
value.ThemePropertyBindings.CollectionChanged += Value_CollectionChanged;
6161
}
@@ -182,7 +182,7 @@ void PaletteListBox_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
182182
// the data context.
183183
static object? GetDataContext(DependencyObject obj)
184184
{
185-
if (obj is FrameworkElement fe && fe.DataContext != null)
185+
if (obj is FrameworkElement fe && fe.DataContext is not null)
186186
{
187187
return fe.DataContext;
188188
}

LottieViewer/Scrubber.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ internal LottieVisualDiagnosticsViewModel? DiagnosticsViewModel
6161
get => _diagnostics;
6262
set
6363
{
64-
if (_diagnostics != null)
64+
if (_diagnostics is not null)
6565
{
6666
_diagnostics.Markers.CollectionChanged -= Markers_CollectionChanged;
6767
}
6868

6969
_diagnostics = value;
7070

71-
if (_diagnostics != null)
71+
if (_diagnostics is not null)
7272
{
7373
_diagnostics.Markers.CollectionChanged += Markers_CollectionChanged;
7474
}
@@ -201,7 +201,7 @@ protected override Size ArrangeOverride(Size finalSize)
201201
// Adjust the position of the markers.
202202
// Set the margin on each of the rectangles in the grid so that they match
203203
// the offsets of the markers in the view model.
204-
if (_diagnostics != null)
204+
if (_diagnostics is not null)
205205
{
206206
for (var i = 0; i < _diagnostics.Markers.Count; i++)
207207
{
@@ -381,7 +381,7 @@ protected override bool GoToStateCore(
381381
var newState = state?.Name;
382382

383383
// Check whether we have already reported this state.
384-
if (newState != null && _previousCommonState != newState)
384+
if (newState is not null && _previousCommonState != newState)
385385
{
386386
_previousCommonState = newState;
387387
scrubber.OnSliderVisualStateChange(newState);

LottieViewer/ViewModel/LottieVisualDiagnosticsViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public object? DiagnosticsObject
3232
ThemePropertyBindings.Clear();
3333
ThemingPropertySet = null;
3434

35-
if (LottieVisualDiagnostics != null)
35+
if (LottieVisualDiagnostics is not null)
3636
{
3737
// Populate the issues list.
3838
foreach (var issue in LottieVisualDiagnostics.JsonParsingIssues.
@@ -46,7 +46,7 @@ public object? DiagnosticsObject
4646

4747
// Populate the marker info.
4848
var composition = LottieVisualDiagnostics.LottieComposition;
49-
if (composition != null)
49+
if (composition is not null)
5050
{
5151
var framesPerSecond = composition.FramesPerSecond;
5252
var duration = composition.Duration.TotalSeconds;
@@ -81,7 +81,7 @@ public object? DiagnosticsObject
8181
}
8282

8383
ThemingPropertySet = LottieVisualDiagnostics.ThemingPropertySet;
84-
if (LottieVisualDiagnostics.ThemePropertyBindings != null)
84+
if (LottieVisualDiagnostics.ThemePropertyBindings is not null)
8585
{
8686
foreach (var binding in LottieVisualDiagnostics.ThemePropertyBindings)
8787
{
@@ -91,7 +91,7 @@ public object? DiagnosticsObject
9191
}
9292

9393
var propertyChangedCallback = PropertyChanged;
94-
if (propertyChangedCallback != null)
94+
if (propertyChangedCallback is not null)
9595
{
9696
propertyChangedCallback(this, new PropertyChangedEventArgs(nameof(DurationText)));
9797
propertyChangedCallback(this, new PropertyChangedEventArgs(nameof(FileName)));

samples/LottieSamples/AnimatedVisuals/LottieLogo1_Modified.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public Color BackgroundColor
8686
set
8787
{
8888
_themeBackgroundColor = value;
89-
if (_themeProperties != null)
89+
if (_themeProperties is not null)
9090
{
9191
_themeProperties.InsertVector4("BackgroundColor", ColorAsVector4((Color)_themeBackgroundColor));
9292
}
@@ -99,7 +99,7 @@ public Color HighlightColor
9999
set
100100
{
101101
_themeHighlightColor = value;
102-
if (_themeProperties != null)
102+
if (_themeProperties is not null)
103103
{
104104
_themeProperties.InsertVector4("HighlightColor", ColorAsVector4((Color)_themeHighlightColor));
105105
}
@@ -112,7 +112,7 @@ public Color TextColor
112112
set
113113
{
114114
_themeTextColor = value;
115-
if (_themeProperties != null)
115+
if (_themeProperties is not null)
116116
{
117117
_themeProperties.InsertVector4("TextColor", ColorAsVector4((Color)_themeTextColor));
118118
}

samples/LottieSamples/MainPage.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private void NavView_Loaded(object sender, RoutedEventArgs e)
5959

6060
private void NavView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
6161
{
62-
if (args.InvokedItemContainer != null)
62+
if (args.InvokedItemContainer is not null)
6363
{
6464
var navItemTag = args.InvokedItemContainer.Tag.ToString();
6565
NavView_Navigate(navItemTag, args.RecommendedNavigationTransitionInfo);
@@ -79,7 +79,7 @@ private void NavView_Navigate(string navItemTag, NavigationTransitionInfo transi
7979

8080
private void On_Navigated(object sender, NavigationEventArgs e)
8181
{
82-
if (ContentFrame.SourcePageType != null)
82+
if (ContentFrame.SourcePageType is not null)
8383
{
8484
var item = _pages.FirstOrDefault(p => p.Page == e.SourcePageType);
8585

samples/LottieSamples/Scenarios/AsyncPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private async Task PlaySegmentsAsync(Segment? segmentForPlayerA, Segment? segmen
9292
var tasks = new[] { segmentForPlayerA?.PlayAsync(PlayerA), segmentForPlayerB?.PlayAsync(PlayerB) };
9393

9494
// Wait for the segments to finish.
95-
await Task.WhenAll(tasks.Where(t => t != null).ToArray());
95+
await Task.WhenAll(tasks.Where(t => t is not null).ToArray());
9696

9797
// Remove the highlight drawn around the playing players.
9898
UpdatePlayerHighlights(false, false);

source/Animatables/ColorGradientStop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override string ToString()
3636
static string ToHex(double value) => ((byte)(value * 255)).ToString("X2");
3737

3838
public bool Equals(ColorGradientStop? other)
39-
=> other != null && other.Offset == Offset && other.Color.Equals(Color);
39+
=> other is not null && other.Offset == Offset && other.Color.Equals(Color);
4040

4141
public override bool Equals(object? obj)
4242
=> Equals(obj as ColorGradientStop);

0 commit comments

Comments
 (0)