From 360b39b369103e7c47fecfa9ecfddfaa35744693 Mon Sep 17 00:00:00 2001 From: MSFT-Tilia Date: Mon, 12 Apr 2021 19:33:40 +0800 Subject: [PATCH] check null before invoking event handlers --- .../Common/AlwaysSelectedCollectionView.cs | 8 ++++---- src/Calculator/Controls/EquationTextBox.cs | 12 ++++++------ src/Calculator/Controls/MathRichEditBox.cs | 6 +++--- src/Calculator/Utils/DispatcherTimerDelayer.cs | 2 +- .../GraphingCalculator/EquationInputArea.xaml.cs | 4 ++-- src/Calculator/Views/TitleBar.xaml.cs | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Calculator/Common/AlwaysSelectedCollectionView.cs b/src/Calculator/Common/AlwaysSelectedCollectionView.cs index 43db8d465..5a89a8e0f 100644 --- a/src/Calculator/Common/AlwaysSelectedCollectionView.cs +++ b/src/Calculator/Common/AlwaysSelectedCollectionView.cs @@ -34,7 +34,7 @@ public bool MoveCurrentTo(object item) if (newCurrentPosition != -1) { m_currentPosition = newCurrentPosition; - CurrentChanged(this, null); + CurrentChanged?.Invoke(this, null); return true; } } @@ -46,7 +46,7 @@ public bool MoveCurrentTo(object item) { Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { - CurrentChanged(this, null); + CurrentChanged?.Invoke(this, null); })).AsTask().Wait(); } return false; @@ -60,7 +60,7 @@ public bool MoveCurrentToPosition(int index) } m_currentPosition = index; - CurrentChanged(this, null); + CurrentChanged?.Invoke(this, null); return true; } @@ -219,7 +219,7 @@ IEnumerator IEnumerable.GetEnumerator() void OnSourceBindableVectorChanged(Windows.UI.Xaml.Interop.IBindableObservableVector source, object e) { Windows.Foundation.Collections.IVectorChangedEventArgs args = (Windows.Foundation.Collections.IVectorChangedEventArgs)e; - VectorChanged(this, args); + VectorChanged?.Invoke(this, args); } public event EventHandler CurrentChanged; diff --git a/src/Calculator/Controls/EquationTextBox.cs b/src/Calculator/Controls/EquationTextBox.cs index b7dbe5cd2..c3da8e40a 100644 --- a/src/Calculator/Controls/EquationTextBox.cs +++ b/src/Calculator/Controls/EquationTextBox.cs @@ -406,7 +406,7 @@ private void OnDeleteButtonClicked(object sender, RoutedEventArgs e) private void OnEquationButtonClicked(object sender, RoutedEventArgs e) { - EquationButtonClicked(this, new RoutedEventArgs()); + EquationButtonClicked?.Invoke(this, new RoutedEventArgs()); SetEquationButtonTooltipAndAutomationName(); } @@ -424,7 +424,7 @@ private void OnRemoveButtonClicked(object sender, RoutedEventArgs e) m_richEditBox.MathText = ""; } - RemoveButtonClicked(this, new RoutedEventArgs()); + RemoveButtonClicked?.Invoke(this, new RoutedEventArgs()); if (m_functionButton != null) { @@ -452,7 +452,7 @@ private void OnColorChooserButtonClicked(object sender, RoutedEventArgs e) private void OnFunctionButtonClicked(object sender, RoutedEventArgs e) { - KeyGraphFeaturesButtonClicked(this, new RoutedEventArgs()); + KeyGraphFeaturesButtonClicked?.Invoke(this, new RoutedEventArgs()); } private void OnFunctionMenuButtonClicked(object sender, RoutedEventArgs e) @@ -463,7 +463,7 @@ private void OnFunctionMenuButtonClicked(object sender, RoutedEventArgs e) m_richEditBox.SubmitEquation(EquationSubmissionSource.FOCUS_LOST); } - KeyGraphFeaturesButtonClicked(this, new RoutedEventArgs()); + KeyGraphFeaturesButtonClicked?.Invoke(this, new RoutedEventArgs()); } private void OnRichEditMenuOpened(object sender, object args) @@ -614,12 +614,12 @@ private void OnEquationSubmitted(object sender, MathRichEditBoxSubmission args) } } - EquationSubmitted(this, args); + EquationSubmitted?.Invoke(this, args); } private void OnEquationFormatRequested(object sender, MathRichEditBoxFormatRequest args) { - EquationFormatRequested(this, args); + EquationFormatRequested?.Invoke(this, args); } } } diff --git a/src/Calculator/Controls/MathRichEditBox.cs b/src/Calculator/Controls/MathRichEditBox.cs index fc2da2e28..73aefac24 100644 --- a/src/Calculator/Controls/MathRichEditBox.cs +++ b/src/Calculator/Controls/MathRichEditBox.cs @@ -150,7 +150,7 @@ public void SubmitEquation(EquationSubmissionSource source) { // Request the final formatting of the text var formatRequest = new MathRichEditBoxFormatRequest(newVal); - FormatRequest(this, formatRequest); + FormatRequest?.Invoke(this, formatRequest); if (!string.IsNullOrEmpty(formatRequest.FormattedText)) { @@ -158,11 +158,11 @@ public void SubmitEquation(EquationSubmissionSource source) } SetValue(MathTextProperty, newVal); - EquationSubmitted(this, new MathRichEditBoxSubmission(true, source)); + EquationSubmitted?.Invoke(this, new MathRichEditBoxSubmission(true, source)); } else { - EquationSubmitted(this, new MathRichEditBoxSubmission(false, source)); + EquationSubmitted?.Invoke(this, new MathRichEditBoxSubmission(false, source)); } } diff --git a/src/Calculator/Utils/DispatcherTimerDelayer.cs b/src/Calculator/Utils/DispatcherTimerDelayer.cs index 6eb2ccb89..4363baaa8 100644 --- a/src/Calculator/Utils/DispatcherTimerDelayer.cs +++ b/src/Calculator/Utils/DispatcherTimerDelayer.cs @@ -37,7 +37,7 @@ public void Stop() private void Timer_Tick(object sender, object e) { m_timer.Stop(); - Action(this, null); + Action?.Invoke(this, null); } private DispatcherTimer m_timer; diff --git a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cs b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cs index 71aeea979..24f9fabcc 100644 --- a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cs +++ b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cs @@ -407,7 +407,7 @@ private void EquationTextBox_RemoveButtonClicked(object sender, RoutedEventArgs private void EquationTextBox_KeyGraphFeaturesButtonClicked(object sender, RoutedEventArgs e) { - KeyGraphFeaturesRequested(this, GetViewModelFromEquationTextBox(sender)); + KeyGraphFeaturesRequested?.Invoke(this, GetViewModelFromEquationTextBox(sender)); } private void EquationTextBox_EquationButtonClicked(object sender, RoutedEventArgs e) @@ -565,7 +565,7 @@ private void VariableAreaTapped(object sender, TappedRoutedEventArgs e) private void EquationTextBox_EquationFormatRequested(object sender, MathRichEditBoxFormatRequest e) { - EquationFormatRequested(sender, e); + EquationFormatRequested?.Invoke(sender, e); } private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) diff --git a/src/Calculator/Views/TitleBar.xaml.cs b/src/Calculator/Views/TitleBar.xaml.cs index 0d8108b48..078bf1e71 100644 --- a/src/Calculator/Views/TitleBar.xaml.cs +++ b/src/Calculator/Views/TitleBar.xaml.cs @@ -199,7 +199,7 @@ private void OnIsAlwaysOnTopModePropertyChanged(bool oldValue, bool newValue) private void AlwaysOnTopButton_Click(object sender, RoutedEventArgs e) { - AlwaysOnTopClick(this, e); + AlwaysOnTopClick?.Invoke(this, e); } private Windows.ApplicationModel.Core.CoreApplicationViewTitleBar m_coreTitleBar;