From 6dc7125f8fbb878b87ed53f07847c48075c7da24 Mon Sep 17 00:00:00 2001 From: Harshit Mishra Date: Fri, 13 Dec 2024 12:33:17 +0530 Subject: [PATCH 1/3] Update: Resolve IDE0030 in src --- src/Microsoft.DotNet.Wpf/src/.editorconfig | 3 --- .../System/Windows/Media/Animation/Clock.cs | 17 ++++++++--------- .../System/Windows/Media/mediaclock.cs | 6 +++--- .../Controls/BooleanToVisibilityConverter.cs | 4 ++-- .../src/Shared/MS/Win32/SafeNativeMethodsCLR.cs | 2 +- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/.editorconfig b/src/Microsoft.DotNet.Wpf/src/.editorconfig index 27d970fb0af..9d90904b146 100644 --- a/src/Microsoft.DotNet.Wpf/src/.editorconfig +++ b/src/Microsoft.DotNet.Wpf/src/.editorconfig @@ -203,9 +203,6 @@ dotnet_diagnostic.IDE0020.severity = suggestion # IDE0029: Use coalesce expression dotnet_diagnostic.IDE0029.severity = suggestion -# IDE0030: Null check can be simplified -dotnet_diagnostic.IDE0030.severity = suggestion - # IDE0031: Use null propagation dotnet_diagnostic.IDE0031.severity = suggestion diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Clock.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Clock.cs index 8c15840bb31..ada8d261b2a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Clock.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Clock.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -236,11 +236,11 @@ public double? CurrentProgress /// - /// Gets a value indicating whether the Clock’s current time is inside the Active period + /// Gets a value indicating whether the Clock’s current time is inside the Active period /// (meaning properties may change frame to frame), inside the Fill period, or Stopped. /// /// - /// You can tell whether you’re in FillBegin or FillEnd by the value of CurrentProgress + /// You can tell whether you’re in FillBegin or FillEnd by the value of CurrentProgress /// (0 for FillBegin, 1 for FillEnd). /// public ClockState CurrentState @@ -486,7 +486,7 @@ protected virtual TimeSpan GetCurrentTimeCore() { Debug.Assert(!IsTimeManager); - return _currentTime.HasValue ? _currentTime.Value : TimeSpan.Zero; + return _currentTime ?? TimeSpan.Zero; } /// @@ -1949,8 +1949,7 @@ private bool ComputeCurrentIteration(TimeSpan parentTime, double parentSpeed, RepeatBehavior repeatBehavior = _timeline.RepeatBehavior; // Apply speed and offset, convert down to TimeSpan - TimeSpan beginTimeForOffsetComputation = _currentIterationBeginTime.HasValue ? _currentIterationBeginTime.Value - : _beginTime.Value; + TimeSpan beginTimeForOffsetComputation = _currentIterationBeginTime ?? _beginTime.Value; TimeSpan offsetFromBegin = MultiplyTimeSpan(parentTime - beginTimeForOffsetComputation, _appliedSpeedRatio); // This may be set redundantly in one case, but simplifies code @@ -2806,7 +2805,7 @@ private void ComputeIntervalsWithHoldEnd( if (parentIntervalCollection.Intersects(fillPeriod)) // We enter or leave Fill period { - TimeSpan relativeBeginTime = _currentIterationBeginTime.HasValue ? _currentIterationBeginTime.Value : _beginTime.Value; + TimeSpan relativeBeginTime = _currentIterationBeginTime ?? _beginTime.Value; ComputeCurrentFillInterval(parentIntervalCollection, relativeBeginTime, endOfActivePeriod.Value, _currentDuration, _appliedSpeedRatio, @@ -2833,7 +2832,7 @@ private void ComputeIntervalsWithParentIntersection( Duration postFillDuration) { // Make sure that our periodic function is aligned to the boundary of the current iteration, regardless of prior slip - TimeSpan relativeBeginTime = _currentIterationBeginTime.HasValue ? _currentIterationBeginTime.Value : _beginTime.Value; + TimeSpan relativeBeginTime = _currentIterationBeginTime ?? _beginTime.Value; RaiseCurrentTimeInvalidated(); @@ -3178,7 +3177,7 @@ private void ComputeSyncEnter(ref TimeIntervalCollection parentIntervalCollectio // With these limitations, we can easily preview our CurrentTime: if (_beginTime.HasValue && currentParentTimePT >= _beginTime.Value) { - TimeSpan relativeBeginTimePT = _currentIterationBeginTime.HasValue ? _currentIterationBeginTime.Value : _beginTime.Value; + TimeSpan relativeBeginTimePT = _currentIterationBeginTime ?? _beginTime.Value; TimeSpan previewCurrentOffsetPT = currentParentTimePT - relativeBeginTimePT; // This is our time offset (not yet scaled by speed) TimeSpan previewCurrentTimeLT = MultiplyTimeSpan(previewCurrentOffsetPT, _appliedSpeedRatio); // This is what our time would be diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/mediaclock.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/mediaclock.cs index ae946039eac..780a5fbfe40 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/mediaclock.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/mediaclock.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -119,10 +119,10 @@ private void Sync() if (_mediaPlayer != null) { double? currentSpeedProperty = this.CurrentGlobalSpeed; - double currentSpeedValue = currentSpeedProperty.HasValue ? currentSpeedProperty.Value : 0; + double currentSpeedValue = currentSpeedProperty ?? 0; TimeSpan? currentTimeProperty = this.CurrentTime; - TimeSpan currentTimeValue = currentTimeProperty.HasValue ? currentTimeProperty.Value : TimeSpan.Zero; + TimeSpan currentTimeValue = currentTimeProperty ?? TimeSpan.Zero; // If speed was potentially changed to 0, make sure we set media's speed to 0 (e.g. pause) before // setting the position to the target frame. Otherwise, the media's scrubbing mechanism would diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/BooleanToVisibilityConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/BooleanToVisibilityConverter.cs index 97ef589e522..f1c4e6f20f7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/BooleanToVisibilityConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/BooleanToVisibilityConverter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -33,7 +33,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn else if (value is Nullable) { Nullable tmp = (Nullable)value; - bValue = tmp.HasValue ? tmp.Value : false; + bValue = tmp ?? false; } return (bValue) ? Visibility.Visible : Visibility.Collapsed; } diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/SafeNativeMethodsCLR.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/SafeNativeMethodsCLR.cs index 02796299c16..24b0f855802 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/SafeNativeMethodsCLR.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/SafeNativeMethodsCLR.cs @@ -307,7 +307,7 @@ public static bool IsCurrentSessionConnectStateWTSActive(int? SessionId = null, IntPtr buffer = IntPtr.Zero; int bytesReturned; - int sessionId = SessionId.HasValue ? SessionId.Value : NativeMethods.WTS_CURRENT_SESSION; + int sessionId = SessionId ?? NativeMethods.WTS_CURRENT_SESSION; bool currentSessionConnectState = defaultResult; try From d145a9e6ef19526973cdb27c5542dd6384a656fd Mon Sep 17 00:00:00 2001 From: Harshit Mishra Date: Mon, 16 Dec 2024 11:50:19 +0530 Subject: [PATCH 2/3] Update: Resolve IDE0031 in src --- src/Microsoft.DotNet.Wpf/src/.editorconfig | 3 - .../SystemXmlExtension.cs | 4 +- .../SystemXmlLinqExtension.cs | 4 +- .../Internal/MarkupCompiler/MarkupCompiler.cs | 7 +- .../Build/Tasks/Windows/FileClassifier.cs | 2 +- .../UpdateManifestForBrowserApplication.cs | 14 +- .../MS/internal/Automation/ElementUtil.cs | 4 +- .../MS/internal/FontCache/FontCacheUtil.cs | 8 +- .../IO/Packaging/ByteRangeDownloader.cs | 7 +- .../MS/internal/IO/Packaging/NetStream.cs | 18 +- .../IO/Packaging/PreloadedPackages.cs | 7 +- .../internal/IO/Packaging/ResponseStream.cs | 9 +- .../MS/internal/Ink/StrokeNodeEnumerator.cs | 4 +- .../MS/internal/Media/VisualTreeUtils.cs | 8 +- .../Media3D/GeneralTransform2DTo3DTo2D.cs | 12 +- .../MS/internal/Media3D/M3DUtil.cs | 7 +- .../MS/internal/Shaping/TypefaceMap.cs | 4 +- .../MS/internal/SynchronizedInputHelper.cs | 7 +- .../MS/internal/SystemDrawingHelper.cs | 15 +- .../internal/TextFormatting/DrawingState.cs | 7 +- .../TextFormatting/LineServicesRun.cs | 4 +- .../internal/TextFormatting/SimpleTextLine.cs | 12 +- .../MS/internal/TextFormatting/TextStore.cs | 6 +- .../System/IO/Packaging/PackWebResponse.cs | 18 +- .../System/IO/Packaging/PackageStore.cs | 9 +- .../Automation/Peers/AutomationPeer.cs | 10 +- .../System/Windows/EventRoute.cs | 7 +- .../System/Windows/FocusWithinProperty.cs | 6 +- .../Windows/Generated/ContentElement.cs | 7 +- .../System/Windows/Generated/UIElement.cs | 7 +- .../Windows/Ink/IncrementalHitTester.cs | 7 +- .../System/Windows/Ink/Stroke2.cs | 16 +- .../System/Windows/Ink/StrokeCollection2.cs | 9 +- .../Input/Command/InputBindingCollection.cs | 7 +- .../Input/Command/InputGestureCollection.cs | 13 +- .../Windows/Input/Command/RoutedCommand.cs | 11 +- .../System/Windows/Input/FocusManager.cs | 7 +- .../System/Windows/Input/InputMethod.cs | 5 +- .../System/Windows/Input/KeyboardDevice.cs | 7 +- .../System/Windows/Input/Manipulation.cs | 7 +- .../Windows/Input/ManipulationDevice.cs | 12 +- .../System/Windows/Input/ManipulationLogic.cs | 7 +- .../System/Windows/Input/MouseDevice.cs | 7 +- .../Input/Stylus/Common/DynamicRenderer.cs | 211 ++++++++---------- .../Input/Stylus/Common/StylusLogic.cs | 12 +- .../Input/Stylus/Common/StylusPlugin.cs | 9 +- .../Stylus/Common/StylusTouchDeviceBase.cs | 4 +- .../Pointer/PointerStylusPlugInManager.cs | 4 +- .../Windows/Input/Stylus/Wisp/PenThread.cs | 7 +- .../Windows/Input/Stylus/Wisp/WispLogic.cs | 4 +- .../Input/Stylus/Wisp/WispStylusDevice.cs | 7 +- .../Stylus/Wisp/WispStylusPlugInCollection.cs | 4 +- .../Stylus/Wisp/WispStylusTouchDevice.cs | 12 +- .../Input/Stylus/Wisp/WispTabletDevice.cs | 7 +- .../Windows/Input/TextServicesContext.cs | 14 +- .../System/Windows/Input/TouchDevice.cs | 7 +- .../Windows/InterOp/HwndMouseInputProvider.cs | 9 +- .../System/Windows/InterOp/HwndTarget.cs | 7 +- .../System/Windows/LayoutManager.cs | 8 +- .../Windows/Media/Animation/Animatable.cs | 22 +- .../Media/Animation/AnimationStorage.cs | 12 +- .../System/Windows/Media/Animation/Clock.cs | 21 +- .../Media/Animation/Generated/Animatable.cs | 7 +- .../System/Windows/Media/Animation/Subtree.cs | 4 +- .../Windows/Media/Animation/TimeManager.cs | 7 +- .../Animation/TimelineClockCollection.cs | 9 +- .../System/Windows/Media/BitmapCacheBrush.cs | 12 +- .../Media/CharacterMetricsDictionary.cs | 4 +- .../System/Windows/Media/DrawingVisual.cs | 14 +- .../Windows/Media/Effects/PixelShader.cs | 7 +- .../Windows/Media/Effects/ShaderEffect.cs | 17 +- .../System/Windows/Media/FormattedText.cs | 8 +- .../Media/Generated/BitmapCacheBrush.cs | 6 +- .../Media/Generated/DrawingContextWalker.cs | 7 +- .../Windows/Media/Generated/DrawingGroup.cs | 12 +- .../Windows/Media/Generated/GeometryGroup.cs | 12 +- .../Windows/Media/Generated/TransformGroup.cs | 12 +- .../Windows/Media/Generated/VisualBrush.cs | 6 +- .../System/Windows/Media/Geometry.cs | 12 +- .../Windows/Media/Imaging/BitmapDecoder.cs | 7 +- .../Media/Imaging/BitmapFrameDecode.cs | 7 +- .../Windows/Media/Imaging/BitmapMetadata.cs | 12 +- .../Windows/Media/Imaging/BitmapSource.cs | 5 +- .../Windows/Media/Imaging/CroppedBitmap.cs | 7 +- .../Media/Imaging/FormatConvertedBitmap.cs | 7 +- .../System/Windows/Media/MediaContext.cs | 12 +- .../System/Windows/Media/PathGeometry.cs | 12 +- .../System/Windows/Media/Pen.cs | 7 +- .../System/Windows/Media/RenderData.cs | 12 +- .../System/Windows/Media/SafeMILHandle.cs | 12 +- .../System/Windows/Media/Visual.cs | 24 +- .../System/Windows/Media/VisualBrush.cs | 12 +- .../Media/textformatting/TextRunCache.cs | 7 +- .../Media3D/Generated/MaterialGroup.cs | 12 +- .../Windows/Media3D/Generated/Model3DGroup.cs | 12 +- .../Media3D/Generated/Transform3DGroup.cs | 12 +- .../Windows/Media3D/Generated/Visual3D.cs | 7 +- .../Windows/Media3D/RayHitTestParameters.cs | 7 +- .../Windows/Media3D/Viewport3DVisual.cs | 12 +- .../System/Windows/Media3D/Visual3D.cs | 16 +- .../Windows/MouseCaptureWithinProperty.cs | 6 +- .../System/Windows/MouseOverProperty.cs | 6 +- .../System/Windows/PresentationSource.cs | 27 +-- .../System/Windows/ReverseInheritProperty.cs | 6 +- .../Windows/StylusCaptureWithinProperty.cs | 6 +- .../System/Windows/StylusOverProperty.cs | 6 +- .../System/Windows/UIElement.cs | 31 +-- .../System/Windows/UIElement3D.cs | 5 +- .../Annotations/Anchoring/PathNode.cs | 5 +- .../Component/AdornerPresentationContext.cs | 4 +- .../Component/AnnotationComponentManager.cs | 5 +- .../Component/AnnotationHighlightLayer.cs | 11 +- .../Component/MarkedHighlightComponent.cs | 8 +- .../AppModel/JournalNavigationScope.cs | 9 +- .../MS/Internal/AppModel/Journaling.cs | 9 +- .../Controls/InkCanvasFeedbackAdorner.cs | 4 +- .../Controls/InkCanvasSelectionAdorner.cs | 7 +- .../MS/Internal/Controls/TemplatedAdorner.cs | 7 +- .../Data/BindingExpressionUncommonField.cs | 7 +- .../MS/Internal/Data/ClrBindingWorker.cs | 45 +--- .../Data/CollectionViewGroupInternal.cs | 26 +-- .../Internal/Data/CollectionViewGroupRoot.cs | 9 +- .../MS/Internal/Data/CollectionViewProxy.cs | 13 +- .../Internal/Data/CompositeCollectionView.cs | 26 +-- .../MS/Internal/Data/DataBindEngine.cs | 7 +- .../Internal/Data/EnumerableCollectionView.cs | 7 +- .../MS/Internal/Data/IndexedEnumerable.cs | 19 +- .../MS/Internal/Data/LiveShapingList.cs | 4 +- .../MS/Internal/Data/ObjectRef.cs | 4 +- .../MS/Internal/Data/PropertyPathWorker.cs | 32 +-- .../Data/StaticPropertyChangedEventManager.cs | 8 +- .../MS/Internal/Data/ViewManager.cs | 7 +- .../MS/Internal/Data/XmlBindingWorker.cs | 6 +- .../MS/Internal/DataStreams.cs | 7 +- .../Globalization/BamlResourceDeserializer.cs | 5 +- .../MS/Internal/Helper.cs | 18 +- .../MS/Internal/IO/Packaging/PackageFilter.cs | 4 +- .../MS/Internal/IO/Packaging/XamlFilter.cs | 12 +- .../MS/Internal/Ink/EditingCoordinator.cs | 19 +- .../MS/Internal/Ink/EraserBehavior.cs | 13 +- .../MS/Internal/Ink/InkCollectionBehavior.cs | 13 +- .../MS/Internal/Ink/LassoHelper.cs | 7 +- .../MS/Internal/Ink/PenCursorManager.cs | 17 +- .../MS/Internal/PtsHost/BreakRecordTable.cs | 7 +- .../MS/Internal/PtsHost/CellParagraph.cs | 4 +- .../MS/Internal/PtsHost/ContainerParagraph.cs | 7 +- .../MS/Internal/PtsHost/FigureParaClient.cs | 7 +- .../MS/Internal/PtsHost/FigureParagraph.cs | 12 +- .../MS/Internal/PtsHost/FloaterParaClient.cs | 7 +- .../MS/Internal/PtsHost/FloaterParagraph.cs | 12 +- .../MS/Internal/PtsHost/FlowDocumentPage.cs | 21 +- .../MS/Internal/PtsHost/Line.cs | 7 +- .../MS/Internal/PtsHost/LineBreakRecord.cs | 7 +- .../Internal/PtsHost/OptimalBreakSession.cs | 19 +- .../MS/Internal/PtsHost/PageVisual.cs | 10 +- .../MS/Internal/PtsHost/PtsCache.cs | 12 +- .../MS/Internal/PtsHost/PtsHost.cs | 7 +- .../MS/Internal/PtsHost/PtsPage.cs | 12 +- .../MS/Internal/PtsHost/Section.cs | 17 +- .../MS/Internal/PtsHost/StructuralCache.cs | 4 +- .../MS/Internal/PtsHost/SubpageParagraph.cs | 12 +- .../MS/Internal/PtsHost/TableParagraph.cs | 9 +- .../MS/Internal/PtsHost/TextParagraph.cs | 4 +- .../MS/Internal/PtsHost/UIElementParagraph.cs | 7 +- .../MS/Internal/SystemCoreHelper.cs | 6 +- .../MS/Internal/SystemDataHelper.cs | 4 +- .../MS/Internal/SystemXmlHelper.cs | 6 +- .../MS/Internal/SystemXmlLinqHelper.cs | 4 +- .../MS/Internal/Text/LineProperties.cs | 4 +- .../MS/Internal/Utility/BindUriHelper.cs | 4 +- .../MS/Internal/WeakHashtable.cs | 4 +- .../MS/Internal/documents/DocumentGrid.cs | 24 +- .../MS/Internal/documents/DocumentGridPage.cs | 7 +- .../MS/Internal/documents/FlowDocumentView.cs | 89 ++------ .../Internal/documents/IFlowDocumentViewer.cs | 22 +- .../MS/Internal/documents/ScrollData.cs | 12 +- .../MS/Internal/documents/TextBoxView.cs | 74 ++---- .../MS/Internal/documents/TextDocumentView.cs | 17 +- .../Microsoft/Win32/CommonDialog.cs | 7 +- .../AnnotationDocumentPaginator.cs | 7 +- .../Windows/Annotations/AnnotationHelper.cs | 4 +- .../Windows/Annotations/AnnotationResource.cs | 7 +- .../System/Windows/Application.cs | 21 +- .../Peers/CalendarAutomationPeer.cs | 20 +- .../Peers/DataGridAutomationPeer.cs | 42 +--- .../Peers/DataGridCellItemAutomationPeer.cs | 11 +- ...ridColumnHeadersPresenterAutomationPeer.cs | 4 +- .../Peers/DataGridItemAutomationPeer.cs | 4 +- .../Peers/DateTimeAutomationPeer.cs | 7 +- .../Peers/DocumentAutomationPeer.cs | 4 +- .../Peers/DocumentViewerBaseAutomationPeer.cs | 7 +- .../Peers/FlowDocumentReaderAutomationPeer.cs | 7 +- .../FlowDocumentScrollViewerAutomationPeer.cs | 7 +- .../Peers/GridViewAutomationPeer.cs | 12 +- .../Peers/GroupItemAutomationPeer.cs | 7 +- .../Automation/Peers/ItemAutomationPeer.cs | 7 +- .../Peers/ItemsControlAutomationPeer.cs | 25 +-- .../Peers/ListBoxItemAutomationPeer.cs | 5 +- .../Peers/SelectorAutomationPeer.cs | 17 +- .../Peers/TreeViewDataItemAutomationPeer.cs | 7 +- .../Peers/TreeViewItemAutomationPeer.cs | 7 +- .../System/Windows/ComponentResourceKey.cs | 4 +- .../Controls/AdornedElementPlaceholder.cs | 8 +- .../System/Windows/Controls/Button.cs | 5 +- .../System/Windows/Controls/Calendar.cs | 14 +- .../System/Windows/Controls/Canvas.cs | 5 +- .../System/Windows/Controls/ComboBox.cs | 28 +-- .../System/Windows/Controls/ComboBoxItem.cs | 22 +- .../System/Windows/Controls/Control.cs | 12 +- .../Controls/CustomDictionarySources.cs | 32 +-- .../System/Windows/Controls/DataGrid.cs | 95 ++------ .../System/Windows/Controls/DataGridCell.cs | 44 ++-- .../Windows/Controls/DataGridCellInfo.cs | 4 +- .../Windows/Controls/DataGridCellsPanel.cs | 15 +- .../System/Windows/Controls/DataGridColumn.cs | 17 +- .../Controls/DataGridColumnCollection.cs | 7 +- .../System/Windows/Controls/DataGridRow.cs | 54 +---- .../System/Windows/Controls/DatePicker.cs | 7 +- .../System/Windows/Controls/Decorator.cs | 7 +- .../Windows/Controls/DeferredTextReference.cs | 7 +- .../System/Windows/Controls/DefinitionBase.cs | 4 +- .../System/Windows/Controls/DockPanel.cs | 7 +- .../System/Windows/Controls/DocumentViewer.cs | 102 ++------- .../System/Windows/Controls/Expander.cs | 7 +- .../Windows/Controls/FlowDocumentReader.cs | 62 ++--- .../Controls/FlowDocumentScrollViewer.cs | 72 ++---- .../System/Windows/Controls/Frame.cs | 44 ++-- .../System/Windows/Controls/Grid.cs | 16 +- .../Windows/Controls/GridViewColumnHeader.cs | 20 +- .../Controls/GridViewHeaderRowPresenter.cs | 17 +- .../Windows/Controls/GridViewRowPresenter.cs | 6 +- .../System/Windows/Controls/GroupItem.cs | 7 +- .../System/Windows/Controls/InkPresenter.cs | 7 +- .../System/Windows/Controls/ItemCollection.cs | 18 +- .../Controls/ItemContainerGenerator.cs | 12 +- .../System/Windows/Controls/ItemsControl.cs | 65 ++---- .../System/Windows/Controls/ItemsPresenter.cs | 13 +- .../System/Windows/Controls/Label.cs | 7 +- .../System/Windows/Controls/ListBox.cs | 12 +- .../System/Windows/Controls/ListBoxItem.cs | 17 +- .../System/Windows/Controls/ListView.cs | 7 +- .../System/Windows/Controls/MediaElement.cs | 32 +-- .../System/Windows/Controls/MenuItem.cs | 25 +-- .../System/Windows/Controls/Page.cs | 9 +- .../System/Windows/Controls/PasswordBox.cs | 17 +- .../Windows/Controls/PopupControlService.cs | 9 +- .../Controls/Primitives/CalendarItem.cs | 17 +- .../Primitives/DataGridCellsPresenter.cs | 11 +- .../Primitives/DataGridColumnHeader.cs | 27 +-- .../DataGridColumnHeadersPresenter.cs | 17 +- .../Primitives/DataGridDetailsPresenter.cs | 10 +- .../Controls/Primitives/DataGridRowHeader.cs | 6 +- .../Controls/Primitives/DocumentPageView.cs | 14 +- .../Controls/Primitives/DocumentViewerBase.cs | 38 +--- .../Windows/Controls/Primitives/Popup.cs | 7 +- .../Windows/Controls/Primitives/RangeBase.cs | 17 +- .../Controls/Primitives/RepeatButton.cs | 10 +- .../Windows/Controls/Primitives/ResizeGrip.cs | 7 +- .../Windows/Controls/Primitives/Selector.cs | 20 +- .../Controls/Primitives/TextBoxBase.cs | 117 ++-------- .../Controls/Primitives/ToggleButton.cs | 7 +- .../Primitives/ToolBarOverflowPanel.cs | 4 +- .../Controls/Primitives/ToolBarPanel.cs | 19 +- .../Windows/Controls/Primitives/Track.cs | 20 +- .../System/Windows/Controls/ProgressBar.cs | 7 +- .../System/Windows/Controls/RichTextBox.cs | 7 +- .../System/Windows/Controls/ScrollViewer.cs | 12 +- .../Windows/Controls/SinglePageViewer.cs | 7 +- .../System/Windows/Controls/Slider.cs | 34 +-- .../Windows/Controls/SoundPlayerAction.cs | 12 +- .../System/Windows/Controls/SpellCheck.cs | 7 +- .../System/Windows/Controls/Stack.cs | 4 +- .../System/Windows/Controls/StickyNote.cs | 50 +---- .../System/Windows/Controls/TabControl.cs | 21 +- .../System/Windows/Controls/TabItem.cs | 7 +- .../System/Windows/Controls/TextAdaptor.cs | 17 +- .../System/Windows/Controls/TextBlock.cs | 19 +- .../System/Windows/Controls/TextSearch.cs | 15 +- .../System/Windows/Controls/ToolBar.cs | 16 +- .../System/Windows/Controls/ToolBarTray.cs | 7 +- .../System/Windows/Controls/ToolTip.cs | 10 +- .../System/Windows/Controls/TreeView.cs | 12 +- .../System/Windows/Controls/TreeViewItem.cs | 31 +-- .../Windows/Controls/UIElementCollection.cs | 12 +- .../System/Windows/Controls/Validation.cs | 12 +- .../Windows/Controls/VirtualizingPanel.cs | 7 +- .../Controls/VirtualizingStackPanel.cs | 60 ++--- .../System/Windows/Data/BindingExpression.cs | 19 +- .../Windows/Data/BindingExpressionBase.cs | 25 +-- .../System/Windows/Data/BindingGroup.cs | 22 +- .../Windows/Data/BindingListCollectionView.cs | 27 +-- .../System/Windows/Data/BindingOperations.cs | 9 +- .../Windows/Data/CollectionContainer.cs | 13 +- .../System/Windows/Data/CollectionView.cs | 17 +- .../Windows/Data/CollectionViewSource.cs | 4 +- .../Windows/Data/CompositeCollection.cs | 7 +- .../System/Windows/Data/ListCollectionView.cs | 40 +--- .../System/Windows/Data/ObjectDataProvider.cs | 4 +- .../Windows/Data/PriorityBindingExpression.cs | 20 +- .../System/Windows/Data/XmlDataProvider.cs | 17 +- .../System/Windows/DescendentsWalkerBase.cs | 4 +- .../System/Windows/Documents/Adorner.cs | 7 +- .../System/Windows/Documents/AdornerLayer.cs | 4 +- .../System/Windows/Documents/AnchoredBlock.cs | 19 +- .../System/Windows/Documents/CaretElement.cs | 16 +- .../Windows/Documents/ColumnResizeAdorner.cs | 7 +- .../Windows/Documents/CompositionAdorner.cs | 9 +- .../Windows/Documents/DocumentSequence.cs | 7 +- .../Documents/DocumentSequenceTextView.cs | 12 +- .../System/Windows/Documents/FixedDocument.cs | 7 +- .../Windows/Documents/FixedFindEngine.cs | 7 +- .../Windows/Documents/FixedTextBuilder.cs | 7 +- .../System/Windows/Documents/FixedTextView.cs | 14 +- .../System/Windows/Documents/FlowDocument.cs | 28 +-- .../System/Windows/Documents/Glyphs.cs | 5 +- .../System/Windows/Documents/Hyperlink.cs | 5 +- .../Windows/Documents/ImmComposition.cs | 6 +- .../Windows/Documents/InlineUIContainer.cs | 19 +- .../System/Windows/Documents/LineBreak.cs | 19 +- .../SpellChecker/SpellChecker.cs | 12 +- .../System/Windows/Documents/PageContent.cs | 7 +- .../Windows/Documents/RtfToXamlReader.cs | 11 +- .../Windows/Documents/RubberbandSelector.cs | 7 +- .../System/Windows/Documents/Run.cs | 19 +- .../System/Windows/Documents/Span.cs | 19 +- .../System/Windows/Documents/Speller.cs | 9 +- .../System/Windows/Documents/SplayTreeNode.cs | 16 +- .../System/Windows/Documents/Table.cs | 7 +- .../System/Windows/Documents/TableCell.cs | 34 +-- .../System/Windows/Documents/TableColumn.cs | 12 +- .../System/Windows/Documents/TableRow.cs | 9 +- .../System/Windows/Documents/TableRowGroup.cs | 7 +- .../System/Windows/Documents/TextContainer.cs | 53 ++--- .../System/Windows/Documents/TextEditor.cs | 39 +--- .../Windows/Documents/TextEditorMouse.cs | 7 +- .../Windows/Documents/TextEditorSpelling.cs | 6 +- .../Windows/Documents/TextEditorTyping.cs | 22 +- .../System/Windows/Documents/TextElement.cs | 15 +- .../Documents/TextElementCollection.cs | 6 +- .../System/Windows/Documents/TextPointer.cs | 10 +- .../System/Windows/Documents/TextSelection.cs | 27 +-- ...tServicesDisplayAttributePropertyRanges.cs | 7 +- .../Windows/Documents/TextServicesHost.cs | 9 +- .../Windows/Documents/TextServicesProperty.cs | 7 +- .../System/Windows/Documents/TextStore.cs | 23 +- .../Windows/Documents/WinRTSpellerInterop.cs | 7 +- .../System/Windows/FrameworkContentElement.cs | 27 +-- .../System/Windows/FrameworkElement.cs | 32 +-- .../System/Windows/FrameworkElementFactory.cs | 4 +- .../System/Windows/FrameworkTemplate.cs | 17 +- .../Generated/FrameworkContentElement.cs | 7 +- .../Windows/Generated/FrameworkElement.cs | 7 +- .../Windows/Input/KeyboardNavigation.cs | 22 +- .../System/Windows/LogicalTreeHelper.cs | 26 +-- .../Windows/Markup/Baml2006/Baml2006Reader.cs | 22 +- .../Markup/Baml2006/Baml2006ReaderFrame.cs | 7 +- .../System/Windows/Markup/BamlReader.cs | 7 +- .../System/Windows/Markup/BamlRecordReader.cs | 28 +-- .../System/Windows/Markup/BamlRecordWriter.cs | 5 +- .../System/Windows/Markup/ParserContext.cs | 17 +- .../Markup/Primitives/ElementMarkupObject.cs | 5 +- .../System/Windows/Markup/StyleXamlParser.cs | 5 +- .../Windows/Markup/TemplateXamlParser.cs | 5 +- .../System/Windows/Markup/WpfXamlLoader.cs | 7 +- .../System/Windows/Markup/XamlParser.cs | 164 +++----------- .../System/Windows/Markup/XamlReader.cs | 14 +- .../System/Windows/Markup/XamlReaderHelper.cs | 2 +- .../System/Windows/Markup/XamlTypeMapper.cs | 35 +-- .../System/Windows/Markup/XmlnsDictionary.cs | 3 +- .../Windows/Media/Animation/Storyboard.cs | 37 +-- .../System/Windows/Navigation/Journal.cs | 12 +- .../Windows/Navigation/NavigationService.cs | 113 +++------- .../Windows/Navigation/NavigationWindow.cs | 12 +- .../System/Windows/PropertyPath.cs | 4 +- .../System/Windows/ResourceDictionary.cs | 18 +- .../System/Windows/Shell/JumpList.cs | 9 +- .../System/Windows/Style.cs | 17 +- .../System/Windows/StyleHelper.cs | 50 ++--- .../System/Windows/SystemResources.cs | 18 +- .../System/Windows/TemplateContent.cs | 12 +- .../System/Windows/TreeWalkHelper.cs | 7 +- .../System/Windows/TriggerBase.cs | 12 +- .../System/Windows/VisualStateManager.cs | 4 +- .../System/Windows/Window.cs | 81 +++---- .../Documents/Application/DocumentManager.cs | 7 +- .../Application/DocumentProperties.cs | 7 +- .../Documents/Application/DocumentStream.cs | 7 +- .../Documents/Application/RightsController.cs | 7 +- .../Application/TransactionalPackage.cs | 7 +- .../DocumentApplicationDocumentViewer.cs | 7 +- .../Documents/DocumentSignatureManager.cs | 17 +- .../Documents/RightsManagementManager.cs | 39 +--- .../AlphaFlattener/BrushProxy.cs | 7 +- .../AlphaFlattener/Flattener.cs | 14 +- .../AlphaFlattener/MetroDevice.cs | 4 +- .../AlphaFlattener/Primitive.cs | 12 +- .../AlphaFlattener/SegmentTree.cs | 7 +- .../Printing/Configuration/HGlobalBuffer.cs | 7 +- .../ReachFramework/Packaging/PartEditor.cs | 12 +- .../ReachFramework/Packaging/XpsDocument.cs | 7 +- .../Packaging/XpsFixedPageReaderWriter.cs | 7 +- .../ReachFramework/Packaging/XpsResource.cs | 18 +- .../PrintConfig/FallbackPTProvider.cs | 7 +- .../PrintConfig/PrtTicket_Base.cs | 12 +- .../PrintSystemException.cs | 17 +- .../Serialization/XpsFontSubsetter.cs | 7 +- .../Serialization/manager/NGCSerializer.cs | 17 +- .../manager/NGCSerializerAsync.cs | 22 +- .../manager/NullPackagingPolicy.cs | 22 +- .../manager/ReachDocumentPageSerializer.cs | 7 +- .../ReachDocumentPageSerializerAsync.cs | 7 +- .../ReachIDocumentPaginatorSerializer.cs | 7 +- .../ReachIDocumentPaginatorSerializerAsync.cs | 7 +- .../manager/ReachObjectContext.cs | 9 +- .../Serialization/manager/ReachSerializer.cs | 7 +- .../manager/ReachSerializerAsync.cs | 7 +- .../manager/XpsOMDocumentPageSerializer.cs | 7 +- .../XpsOMDocumentPaginatorSerializer.cs | 7 +- .../XpsOMDocumentPaginatorSerializerAsync.cs | 7 +- .../manager/XpsOMPackagingPolicy.cs | 17 +- .../manager/XpsPackagingPolicy.cs | 22 +- .../manager/XpsSerializationManager.cs | 12 +- .../SerializerFactory/XpsSerializerWriter.cs | 12 +- .../IO/Packaging/PackagingUtilities.cs | 3 +- .../Internal/ReaderWriterLockSlimWrapper.cs | 5 +- .../src/Shared/MS/Utility/FrugalList.cs | 12 +- .../src/Shared/MS/Utility/FrugalMap.cs | 20 +- .../src/Shared/MS/Utility/Maps.cs | 7 +- .../Windows/Markup/XmlWrappingReader.cs | 4 +- .../Automation/Peers/RibbonAutomationPeer.cs | 7 +- ...RibbonGalleryCategoryDataAutomationPeer.cs | 7 +- .../Peers/RibbonGalleryItemAutomationPeer.cs | 12 +- .../RibbonGalleryItemDataAutomationPeer.cs | 7 +- .../Peers/RibbonGroupAutomationPeer.cs | 7 +- .../Peers/RibbonGroupDataAutomationPeer.cs | 7 +- .../Peers/RibbonMenuItemAutomationPeer.cs | 12 +- .../Peers/RibbonTabAutomationPeer.cs | 7 +- .../Windows/Controls/Generated/TreeHelper.cs | 12 +- .../Windows/Controls/KeyTipAdorner.cs | 7 +- .../Windows/Controls/KeyTipService.cs | 32 +-- .../RibbonContextualTabGroupsPanel.cs | 7 +- .../RibbonGalleryCategoriesPanel.cs | 9 +- .../RibbonQuickAccessToolBarPanel.cs | 9 +- .../Primitives/RibbonTabHeadersPanel.cs | 14 +- .../Ribbon/Primitives/RibbonTabsPanel.cs | 4 +- .../Windows/Controls/Ribbon/Ribbon.cs | 47 +--- .../Windows/Controls/Ribbon/RibbonComboBox.cs | 18 +- .../Controls/Ribbon/RibbonContentPresenter.cs | 9 +- .../RibbonContextualTabGroupItemsControl.cs | 12 +- .../Windows/Controls/Ribbon/RibbonControl.cs | 4 +- .../Controls/Ribbon/RibbonControlService.cs | 12 +- .../Windows/Controls/Ribbon/RibbonGallery.cs | 7 +- .../Controls/Ribbon/RibbonGalleryCategory.cs | 7 +- .../Controls/Ribbon/RibbonGalleryItem.cs | 4 +- .../Windows/Controls/Ribbon/RibbonGroup.cs | 17 +- .../Windows/Controls/Ribbon/RibbonHelper.cs | 65 ++---- .../Controls/Ribbon/RibbonMenuButton.cs | 19 +- .../Windows/Controls/Ribbon/RibbonMenuItem.cs | 22 +- .../Ribbon/RibbonQuickAccessToolBar.cs | 22 +- .../Controls/Ribbon/RibbonSplitButton.cs | 17 +- .../Controls/Ribbon/RibbonSplitMenuItem.cs | 7 +- .../Windows/Controls/Ribbon/RibbonTab.cs | 52 +---- .../Controls/Ribbon/RibbonTabHeader.cs | 7 +- .../Ribbon/RibbonTabHeaderItemsControl.cs | 7 +- .../Windows/Controls/TextSearchInternal.cs | 7 +- .../Microsoft/Windows/Input/CommandHelpers.cs | 10 +- .../Input/Manipulations/InertiaProcessor2D.cs | 15 +- .../Manipulations/ManipulationSequence.cs | 10 +- .../Xaml/Context/ObjectWriterContext.cs | 6 +- .../System/Xaml/Context/XamlCommonFrame.cs | 10 +- .../Xaml/InfosetObjects/DeferredWriter.cs | 5 +- .../Xaml/InfosetObjects/XamlObjectWriter.cs | 2 +- .../System/Xaml/MS/Impl/XmlNsInfo.cs | 2 +- .../System/Xaml/Runtime/ClrObjectRuntime.cs | 5 +- .../System/Xaml/Schema/TypeReflector.cs | 5 +- .../System/Xaml/Schema/XamlTypeInvoker.cs | 4 +- .../System.Xaml/System/Xaml/XamlException.cs | 2 +- .../src/System.Xaml/System/Xaml/XamlMember.cs | 4 +- .../System/Xaml/XamlObjectReader.cs | 9 +- .../System/Xaml/XamlSchemaContext.cs | 10 +- .../src/System.Xaml/System/Xaml/XamlType.cs | 6 +- .../Microsoft/Windows/Themes/ButtonChrome.cs | 7 +- .../Microsoft/Windows/Themes/ListBoxChrome.cs | 7 +- .../Microsoft/Windows/Themes/ButtonChrome.cs | 7 +- .../Microsoft/Windows/Themes/ListBoxChrome.cs | 7 +- .../Microsoft/Windows/Themes/ButtonChrome.cs | 7 +- .../Microsoft/Windows/Themes/ButtonChrome.cs | 7 +- .../MS/Internal/Automation/WinEventWrap.cs | 7 +- .../AutomationProxies/MSAAWinEventWrap.cs | 7 +- .../AutomationProxies/NonClientArea.cs | 32 +-- .../AutomationProxies/WinFormsSpinner.cs | 12 +- .../AutomationProxies/WindowsAltTab.cs | 7 +- .../AutomationProxies/WindowsComboBox.cs | 7 +- .../AutomationProxies/WindowsListBox.cs | 17 +- .../AutomationProxies/WindowsListView.cs | 12 +- .../AutomationProxies/WindowsScrollBar.cs | 7 +- .../AutomationProxies/WindowsStatic.cs | 5 +- .../AutomationProxies/WindowsSysHeader.cs | 17 +- .../Internal/AutomationProxies/WindowsTab.cs | 7 +- .../AutomationProxies/WindowsToolbar.cs | 7 +- .../AutomationProxies/WindowsTreeView.cs | 7 +- .../AutomationProxies/WindowsUpDown.cs | 7 +- .../ComponentModel/DPCustomTypeDescriptor.cs | 4 +- .../CompoundFile/ContainerUtilities.cs | 5 +- .../CompoundFile/NativeCompoundFileAPIs.cs | 5 +- .../IO/Packaging/SparseMemoryStream.cs | 7 +- .../Packaging/XmlDigitalSignatureProcessor.cs | 3 +- .../MS/Internal/InheritanceContextHelper.cs | 5 +- .../RightsManagement/ClientSession.cs | 5 +- .../RightsManagement/IssuanceLicense.cs | 16 +- .../src/WindowsBase/MS/Internal/Utilities.cs | 5 +- .../CompoundFile/DataSpaceManager.cs | 3 +- .../System/IO/Packaging/EncryptedPackage.cs | 40 +--- .../System/Windows/DependencyObject.cs | 5 +- .../WindowsBase/System/Windows/Freezable.cs | 10 +- .../WindowsBase/System/Windows/NameScope.cs | 5 +- .../System/Windows/PropertyMetadata.cs | 16 +- .../System/Windows/Threading/Dispatcher.cs | 45 +--- .../Threading/DispatcherHookEventArgs.cs | 2 +- .../Windows/Threading/DispatcherObject.cs | 5 +- .../Windows/Threading/DispatcherOperation.cs | 5 +- .../System/Windows/Integration/ElementHost.cs | 17 +- .../Windows/Integration/WindowsFormsHost.cs | 37 +-- .../WindowsFormsHostPropertyMap.cs | 6 +- 524 files changed, 2095 insertions(+), 5262 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/.editorconfig b/src/Microsoft.DotNet.Wpf/src/.editorconfig index 9d90904b146..292c2eeef85 100644 --- a/src/Microsoft.DotNet.Wpf/src/.editorconfig +++ b/src/Microsoft.DotNet.Wpf/src/.editorconfig @@ -203,9 +203,6 @@ dotnet_diagnostic.IDE0020.severity = suggestion # IDE0029: Use coalesce expression dotnet_diagnostic.IDE0029.severity = suggestion -# IDE0031: Use null propagation -dotnet_diagnostic.IDE0031.severity = suggestion - # IDE0034: Simplify 'default' expression dotnet_diagnostic.IDE0034.severity = suggestion diff --git a/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXml/SystemXmlExtension.cs b/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXml/SystemXmlExtension.cs index fa40c875578..05b08b3cb5f 100644 --- a/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXml/SystemXmlExtension.cs +++ b/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXml/SystemXmlExtension.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -171,7 +171,7 @@ private static XmlNamespaceManager GetXmlNamespaceManager(DependencyObject targe if (nsmgr == null) { XmlDataProvider xdp = Helper.XmlDataProviderForElement(target); - nsmgr = (xdp != null) ? xdp.XmlNamespaceManager : null; + nsmgr = xdp?.XmlNamespaceManager; } return nsmgr; diff --git a/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXmlLinq/SystemXmlLinqExtension.cs b/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXmlLinq/SystemXmlLinqExtension.cs index 5a0a67b906f..b9e31f38c1b 100644 --- a/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXmlLinq/SystemXmlLinqExtension.cs +++ b/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXmlLinq/SystemXmlLinqExtension.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -37,7 +37,7 @@ internal override bool IsXElement(object item) internal override string GetXElementTagName(object item) { XName name = ((XElement)item).Name; - return (name != null) ? name.ToString() : null; + return name?.ToString(); } // XLinq exposes two synthetic properties - Elements and Descendants - diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs index e13d4188ec2..ca9224cabc4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs @@ -565,10 +565,7 @@ private void _Compile(string relativeSourceFile, bool pass2) } - if (SourceFileInfo != null) - { - SourceFileInfo.CloseStream(); - } + SourceFileInfo?.CloseStream(); if (bamlStream != null) { @@ -1930,7 +1927,7 @@ private CodeExpression GetEventDelegate(CodeContext cc, MemberInfo miEvent, stri // Fetch the EventHandlerType from either the EventInfo or the MethodInfo // for the Add{Propertyname}Handler method's MethodInfo Type eventHandlerType = GetEventHandlerType(miEvent); - string [] typeArgsList = cc != null ? cc.GenericTypeArgs : null; + string [] typeArgsList = cc?.GenericTypeArgs; cdce.DelegateType = GenerateConstructedTypeReference(eventHandlerType, typeArgsList, eventTarget, eventTargetName, eventName); cdce.MethodName = eventHandler.Trim() + (subClassed ? HELPER : string.Empty); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/FileClassifier.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/FileClassifier.cs index a9509fa0300..9b9d423ab82 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/FileClassifier.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/FileClassifier.cs @@ -164,7 +164,7 @@ public override bool Execute() /// public string Culture { - get { return _culture != null ? _culture.ToLower(CultureInfo.InvariantCulture) : null; } + get { return _culture?.ToLower(CultureInfo.InvariantCulture); } set { _culture = value; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UpdateManifestForBrowserApplication.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UpdateManifestForBrowserApplication.cs index e19ce88010a..f941910d0aa 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UpdateManifestForBrowserApplication.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UpdateManifestForBrowserApplication.cs @@ -90,11 +90,8 @@ public override bool Execute() } finally { - if (manifestReader != null) - { - // Close the manifest reader - manifestReader.Close(); - } + // Close the manifest reader + manifestReader?.Close(); } // NOTE: @@ -124,11 +121,8 @@ public override bool Execute() } finally { - if (manifestWriter != null) - { - // Close the manifest writer - manifestWriter.Close(); - } + // Close the manifest writer + manifestWriter?.Close(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/ElementUtil.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/ElementUtil.cs index 97cb39b03c9..2a1cd83f179 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/ElementUtil.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/ElementUtil.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -156,7 +156,7 @@ internal static Visual GetElementFromPoint( IntPtr hwnd, Visual root, Point poin Point pointClient = PointUtil.ScreenToClient( pointScreen, hwndSource ); Point pointRoot = PointUtil.ClientToRoot(pointClient, hwndSource); PointHitTestResult result = VisualTreeUtils.AsNearestPointHitTestResult(VisualTreeHelper.HitTest(root, pointRoot)); - Visual visual = (result != null) ? result.VisualHit : null; + Visual visual = result?.VisualHit; return visual; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontCacheUtil.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontCacheUtil.cs index 00b346c4733..27b30406158 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontCacheUtil.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontCacheUtil.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -798,10 +798,8 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (_viewHandle != null) - _viewHandle.Dispose(); - if (_mappingHandle != null) - _mappingHandle.Dispose(); + _viewHandle?.Dispose(); + _mappingHandle?.Dispose(); } // We only handle flat disk files read only, should never be writeable. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs index e4a41f030c4..f021f9613a3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -567,10 +567,7 @@ private void ResponseCallback(IAsyncResult ar) } finally { - if (webResponse != null) - { - webResponse.Close(); - } + webResponse?.Close(); // bytes requested are downloaded or errored out // inform the caller that these ranges are available diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/NetStream.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/NetStream.cs index 7e02d8cdc4e..afa7c37c727 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/NetStream.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/NetStream.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -396,10 +396,8 @@ protected override void Dispose(bool disposing) _disposed = true; // release any blocked threads - Set() does not throw any exceptions - if (_readEventHandles[(int)ReadEvent.FullDownloadReadEvent] != null) - _readEventHandles[(int)ReadEvent.FullDownloadReadEvent].Set(); - if (_readEventHandles[(int)ReadEvent.ByteRangeReadEvent] != null) - _readEventHandles[(int)ReadEvent.ByteRangeReadEvent].Set(); + _readEventHandles[(int)ReadEvent.FullDownloadReadEvent]?.Set(); + _readEventHandles[(int)ReadEvent.ByteRangeReadEvent]?.Set(); // Free ByteRangeDownloader FreeByteRangeDownloader(); @@ -417,10 +415,7 @@ protected override void Dispose(bool disposing) } // Free Full Download - if (_responseStream != null) - { - _responseStream.Close(); - } + _responseStream?.Close(); FreeTempFile(); #if DEBUG @@ -1181,10 +1176,7 @@ private void ReleaseFullDownloadResources() finally { // FreeFullDownload - if (_responseStream != null) - { - _responseStream.Close(); - } + _responseStream?.Close(); } } finally diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/PreloadedPackages.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/PreloadedPackages.cs index 1d575317762..d186e2d91b3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/PreloadedPackages.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/PreloadedPackages.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -133,10 +133,7 @@ internal static void RemovePackage(Uri uri) lock (_globalLock) { - if (_packagePairs != null) - { - _packagePairs.Remove(uri); - } + _packagePairs?.Remove(uri); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ResponseStream.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ResponseStream.cs index 37a7dc4ec76..fcafc5fabc6 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ResponseStream.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ResponseStream.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -239,11 +239,8 @@ protected override void Dispose(bool disposing) // close the Part or NetStream _innerStream.Close(); - if (_owningStream != null) - { - // in this case, the innerStream was the part so this is the NetStream - _owningStream.Close(); - } + // in this case, the innerStream was the part so this is the NetStream + _owningStream?.Close(); } } finally diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StrokeNodeEnumerator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StrokeNodeEnumerator.cs index 1ba12da8e7d..6cfc1a76a3e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StrokeNodeEnumerator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StrokeNodeEnumerator.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -84,7 +84,7 @@ internal StrokeNodeIterator(StylusShape nodeShape) /// drawing attributes internal StrokeNodeIterator(DrawingAttributes drawingAttributes) : this( null, //stylusPoints - StrokeNodeOperations.CreateInstance((drawingAttributes == null ? null : drawingAttributes.StylusShape)), + StrokeNodeOperations.CreateInstance((drawingAttributes?.StylusShape)), (drawingAttributes == null ? false : !drawingAttributes.IgnorePressure)) //usePressure { } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media/VisualTreeUtils.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media/VisualTreeUtils.cs index 00838c1e4ea..c6414b9822c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media/VisualTreeUtils.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media/VisualTreeUtils.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -85,9 +85,9 @@ internal static void SetFlagsToRoot(DependencyObject element, bool value, Visual { visual.SetFlagsToRoot(value, flags); } - else if (visual3D != null) + else { - visual3D.SetFlagsToRoot(value, flags); + visual3D?.SetFlagsToRoot(value, flags); } } @@ -281,7 +281,7 @@ internal static bool AsVisualInternal(DependencyObject element, out Visual visua { Debug.Fail(String.Format( "'{0}' is not a Visual or Visual3D. Caller is responsible for guaranteeing that element is a Visual type.", - element != null ? element.GetType() : null)); + element?.GetType())); } return castSucceeded; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media3D/GeneralTransform2DTo3DTo2D.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media3D/GeneralTransform2DTo3DTo2D.cs index 24011ff32f6..29def76269e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media3D/GeneralTransform2DTo3DTo2D.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media3D/GeneralTransform2DTo3DTo2D.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -101,10 +101,7 @@ internal GeneralTransform2DTo3DTo2D(Viewport2DVisual3D visual3D, Visual fromVisu // store the inverse as well _transform2DInverse = (GeneralTransform)_transform2D.Inverse; - if (_transform2DInverse != null) - { - _transform2DInverse.Freeze(); - } + _transform2DInverse?.Freeze(); // make a copy of the camera and other values on the Viewport3D Viewport3DVisual viewport3D = (Viewport3DVisual)VisualTreeHelper.GetContainingVisual2D(visual3D); @@ -120,10 +117,7 @@ internal GeneralTransform2DTo3DTo2D(Viewport2DVisual3D visual3D, Visual fromVisu _objectToViewport = visual3D.TransformToAncestor(viewport3D); // if the transform was not possible, it could be null - check before freezing - if (_objectToViewport != null) - { - _objectToViewport.Freeze(); - } + _objectToViewport?.Freeze(); // store the needed transformations for the various operations _worldTransformation = M3DUtil.GetWorldTransformationMatrix(visual3D); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media3D/M3DUtil.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media3D/M3DUtil.cs index 19ab913b6c6..5f5ee8dd4de 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media3D/M3DUtil.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Media3D/M3DUtil.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -532,10 +532,7 @@ internal static Matrix3D GetWorldTransformationMatrix(Visual3D visual3DStart, ou Transform3D transform = (Transform3D)visual3D.GetValue(Visual3D.TransformProperty); - if (transform != null) - { - transform.Append(ref worldTransform); - } + transform?.Append(ref worldTransform); dependencyObject = VisualTreeHelper.GetParent(dependencyObject); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Shaping/TypefaceMap.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Shaping/TypefaceMap.cs index f850633e82e..243ee4cef22 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Shaping/TypefaceMap.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Shaping/TypefaceMap.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -606,7 +606,7 @@ out cchNextValid else if (!string.IsNullOrEmpty(targetFamilyName)) { // The base Uri used for resolving target family names is the Uri of the composite font. - Uri baseUri = (canonicalFamilyReference != null) ? canonicalFamilyReference.LocationUri : null; + Uri baseUri = canonicalFamilyReference?.LocationUri; // map to the target of the family map cchAdvance = MapByFontFamilyName( diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs index c60740c0b42..1f598043918 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -146,10 +146,7 @@ internal static void AddParentPreOpportunityHandler(DependencyObject o, EventRou else { UIElement3D e3D = logicalParent as UIElement3D; - if (e3D != null) - { - e3D.AddSynchronizedInputPreOpportunityHandler(route, args); - } + e3D?.AddSynchronizedInputPreOpportunityHandler(route, args); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SystemDrawingHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SystemDrawingHelper.cs index abbd269b24f..829d48696fe 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SystemDrawingHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SystemDrawingHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -45,14 +45,14 @@ internal static IntPtr GetHandleFromMetafile(Object data) internal static Object GetMetafileFromHemf(IntPtr hMetafile) { SystemDrawingExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemDrawing(force:true); - return (extensions != null) ? extensions.GetMetafileFromHemf(hMetafile) : null; + return extensions?.GetMetafileFromHemf(hMetafile); } // Get a bitmap from the given data (either BitmapSource or Bitmap) internal static object GetBitmap(object data) { SystemDrawingExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemDrawing(force:true); - return (extensions != null) ? extensions.GetBitmap(data) : null; + return extensions?.GetBitmap(data); } // Get a bitmap handle from the given data (either BitmapSource or Bitmap) @@ -87,17 +87,14 @@ internal static IntPtr ConvertMetafileToHBitmap(IntPtr handle) internal static Stream GetCommentFromGifStream(Stream stream) { SystemDrawingExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemDrawing(force:true); - return (extensions != null) ? extensions.GetCommentFromGifStream(stream) : null; + return extensions?.GetCommentFromGifStream(stream); } // write a metafile stream to the output stream in PNG format internal static void SaveMetafileToImageStream(MemoryStream metafileStream, Stream imageStream) { SystemDrawingExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemDrawing(force:true); - if (extensions != null) - { - extensions.SaveMetafileToImageStream(metafileStream, imageStream); - } + extensions?.SaveMetafileToImageStream(metafileStream, imageStream); } //returns bitmap snapshot of selected area @@ -105,7 +102,7 @@ internal static void SaveMetafileToImageStream(MemoryStream metafileStream, Stre internal static object GetBitmapFromBitmapSource(object source) { SystemDrawingExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemDrawing(force:true); - return (extensions != null) ? extensions.GetBitmapFromBitmapSource(source) : null; + return extensions?.GetBitmapFromBitmapSource(source); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/DrawingState.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/DrawingState.cs index 43293f55180..d0df45f7948 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/DrawingState.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/DrawingState.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -105,10 +105,7 @@ internal void UnsetGuidelineY() public void Dispose() { // clear the guideline at line's baseline - if (_drawingContext != null) - { - _drawingContext.Pop(); - } + _drawingContext?.Pop(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/LineServicesRun.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/LineServicesRun.cs index 6ad5695e70c..6f6cfddc936 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/LineServicesRun.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/LineServicesRun.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -530,7 +530,7 @@ internal CultureInfo TextCulture { get { - return CultureMapper.GetSpecificCulture(RunProp != null ? RunProp.CultureInfo : null); + return CultureMapper.GetSpecificCulture(RunProp?.CultureInfo); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/SimpleTextLine.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/SimpleTextLine.cs index 84e2ce2c896..d7b6b02f7e5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/SimpleTextLine.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/SimpleTextLine.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -585,10 +585,7 @@ Point origin int idealXRelativeToOrigin = _idealOffsetUnRounded; double y = origin.Y + Baseline; - if (drawingContext != null) - { - drawingContext.PushGuidelineY1(y); - } + drawingContext?.PushGuidelineY1(y); Rect boundingBox = Rect.Empty; @@ -610,10 +607,7 @@ Point origin } finally { - if (drawingContext != null) - { - drawingContext.Pop(); - } + drawingContext?.Pop(); } if(boundingBox.IsEmpty) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextStore.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextStore.cs index d5764568f4a..058f664b5a1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextStore.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextStore.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -273,7 +273,7 @@ out charFlags // store up the run info in a span indexed by actual character index runInfoVector.SetReference(cch, stringLength, runInfo); - TextEffectCollection textEffects = (runInfo.Properties != null) ? runInfo.Properties.TextEffects : null; + TextEffectCollection textEffects = runInfo.Properties?.TextEffects; if (textEffects != null && textEffects.Count != 0) { SetTextEffectsVector(textEffectsVector, cch, runInfo, textEffects); @@ -913,7 +913,7 @@ out byte[] bidiLevels int ich = resolvedLength; do { - CultureInfo culture = CultureMapper.GetSpecificCulture(currentRunInfo.Properties == null ? null : currentRunInfo.Properties.CultureInfo); + CultureInfo culture = CultureMapper.GetSpecificCulture(currentRunInfo.Properties?.CultureInfo); DirectionClass europeanNumberOverride = _bidiState.GetEuropeanNumberClassOverride(culture); // diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackWebResponse.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackWebResponse.cs index 4c2233a0017..475ef596260 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackWebResponse.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackWebResponse.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -532,10 +532,7 @@ protected override void Dispose(bool disposing) _responseAvailable.Close(); // this call can not throw an exception // timer - if (_timeoutTimer != null) - { - _timeoutTimer.Dispose(); - } + _timeoutTimer?.Dispose(); } finally { @@ -697,8 +694,7 @@ internal void Close() // Prevent recursion - this sync-protected member is safe to set in a CachedResponse // mode because we have no other thread in operation. _parent._disposed = true; - if (_parent._responseStream != null) - _parent._responseStream.Close(); + _parent._responseStream?.Close(); } finally { @@ -770,8 +766,7 @@ private void ResponseCallback(IAsyncResult ar) if (!_disposed) { // dispose the timer - it is no longer needed - if (_timeoutTimer != null) - _timeoutTimer.Dispose(); + _timeoutTimer?.Dispose(); #if DEBUG if (PackWebRequestFactory._traceSwitch.Enabled) System.Diagnostics.Trace.TraceInformation( @@ -904,10 +899,7 @@ private void TimeoutCallback(Object stateInfo) } #endif // clean up - if (_timeoutTimer != null) - { - _timeoutTimer.Dispose(); - } + _timeoutTimer?.Dispose(); } finally { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs index 74ef34e359b..5a476a1b877 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -127,11 +127,8 @@ public static void RemovePackage(Uri uri) lock (_globalLock) { - if (_packages != null) - { - // If the key doesn't exist, it is no op - _packages.Remove(uri); - } + // If the key doesn't exist, it is no op + _packages?.Remove(uri); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Automation/Peers/AutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Automation/Peers/AutomationPeer.cs index 3dbc0bc6b97..055574d733e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Automation/Peers/AutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Automation/Peers/AutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -2120,13 +2120,9 @@ internal void InvalidateAncestorsRecursive() if (!AncestorsInvalid) { AncestorsInvalid = true; - if (EventsSource != null) - { - EventsSource.InvalidateAncestorsRecursive(); - } + EventsSource?.InvalidateAncestorsRecursive(); - if (_parent != null) - _parent.InvalidateAncestorsRecursive(); + _parent?.InvalidateAncestorsRecursive(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRoute.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRoute.cs index 50aa4789314..4f817647a02 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRoute.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRoute.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -508,10 +508,7 @@ internal void Clear() _routeItemList.Clear(); - if (_branchNodeStack != null) - { - _branchNodeStack.Clear(); - } + _branchNodeStack?.Clear(); _sourceItemList.Clear(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/FocusWithinProperty.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/FocusWithinProperty.cs index 9ec2ad6f146..0ee84df18ba 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/FocusWithinProperty.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/FocusWithinProperty.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -37,9 +37,9 @@ internal override void FireNotifications(UIElement uie, ContentElement ce, UIEle { ce.RaiseIsKeyboardFocusWithinChanged(args); } - else if (uie3D != null) + else { - uie3D.RaiseIsKeyboardFocusWithinChanged(args); + uie3D?.RaiseIsKeyboardFocusWithinChanged(args); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/ContentElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/ContentElement.cs index 726d7a0d30b..3e1850b2df7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/ContentElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/ContentElement.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -221,10 +221,7 @@ internal sealed override void EvaluateAnimatedValueCore( { AnimationStorage storage = AnimationStorage.GetStorage(this, dp); - if (storage != null) - { - storage.EvaluateAnimatedValue(metadata, ref entry); - } + storage?.EvaluateAnimatedValue(metadata, ref entry); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/UIElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/UIElement.cs index 89799d67868..70481f4d567 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/UIElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/UIElement.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -221,10 +221,7 @@ internal sealed override void EvaluateAnimatedValueCore( { AnimationStorage storage = AnimationStorage.GetStorage(this, dp); - if (storage != null) - { - storage.EvaluateAnimatedValue(metadata, ref entry); - } + storage?.EvaluateAnimatedValue(metadata, ref entry); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/IncrementalHitTester.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/IncrementalHitTester.cs index 9e01c8f03d0..fbea4f5baa1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/IncrementalHitTester.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/IncrementalHitTester.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -253,10 +253,7 @@ private void RebuildStrokeInfoCache() { StrokeInfo strokeInfo = _strokeInfos[x]; - if (strokeInfo != null) - { - strokeInfo.Detach(); - } + strokeInfo?.Detach(); } _strokeInfos = newStrokeInfos; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Stroke2.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Stroke2.cs index 6e4ad779151..a6304d6a44c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Stroke2.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Stroke2.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -240,11 +240,8 @@ public bool HitTest(Rect bounds, int percentageWithinBounds) } finally { - if (strokeInfo != null) - { - //detach from event handlers, or else we leak. - strokeInfo.Detach(); - } + //detach from event handlers, or else we leak. + strokeInfo?.Detach(); } } @@ -296,11 +293,8 @@ public bool HitTest(IEnumerable lassoPoints, int percentageWithinLasso) } finally { - if (strokeInfo != null) - { - //detach from event handlers, or else we leak. - strokeInfo.Detach(); - } + //detach from event handlers, or else we leak. + strokeInfo?.Detach(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs index af321245a6f..95f0c778851 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -130,11 +130,8 @@ public StrokeCollection HitTest(IEnumerable lassoPoints, int percentageWi } finally { - if (strokeInfo != null) - { - //detach from event handlers, or else we leak. - strokeInfo.Detach(); - } + //detach from event handlers, or else we leak. + strokeInfo?.Detach(); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputBindingCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputBindingCollection.cs index 92106aae29b..29971d57d4c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputBindingCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputBindingCollection.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -421,10 +421,7 @@ public bool Contains(InputBinding key) /// start index in the current list to copy public void CopyTo(InputBinding[] inputBindings, int index) { - if (_innerBindingList != null) - { - _innerBindingList.CopyTo(inputBindings, index); - } + _innerBindingList?.CopyTo(inputBindings, index); } #endregion Public diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputGestureCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputGestureCollection.cs index 2ee4eff4e94..0ae63317e2e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputGestureCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputGestureCollection.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -167,7 +167,7 @@ public InputGesture this[int index] { get { - return (_innerGestureList != null ? _innerGestureList[index] : null); + return (_innerGestureList?[index]); } set { @@ -227,8 +227,7 @@ public void RemoveAt(int index) if (IsReadOnly) throw new NotSupportedException(SR.ReadOnlyInputGesturesCollection); - if (_innerGestureList != null) - _innerGestureList.RemoveAt(index); + _innerGestureList?.RemoveAt(index); } /// @@ -309,8 +308,7 @@ public void Insert(int index, InputGesture inputGesture) if (inputGesture == null) throw new NotSupportedException(SR.CollectionOnlyAcceptsInputGestures); - if (_innerGestureList != null) - _innerGestureList.Insert(index, inputGesture); + _innerGestureList?.Insert(index, inputGesture); } /// @@ -392,8 +390,7 @@ public bool Contains(InputGesture key) /// start index of items to copy public void CopyTo(InputGesture[] inputGestures, int index) { - if (_innerGestureList != null) - _innerGestureList.CopyTo(inputGestures, index); + _innerGestureList?.CopyTo(inputGestures, index); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/RoutedCommand.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/RoutedCommand.cs index e341cf3199e..f4d0db6ae78 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/RoutedCommand.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/RoutedCommand.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -395,10 +395,7 @@ private bool ExecuteImpl(object parameter, IInputElement target, bool userInitia else { targetAsUIElement3D = target as UIElement3D; - if (targetAsUIElement3D != null) - { - targetAsUIElement3D.RaiseEvent(args, userInitiated); - } + targetAsUIElement3D?.RaiseEvent(args, userInitiated); } } @@ -413,9 +410,9 @@ private bool ExecuteImpl(object parameter, IInputElement target, bool userInitia { targetAsContentElement.RaiseEvent(args, userInitiated); } - else if (targetAsUIElement3D != null) + else { - targetAsUIElement3D.RaiseEvent(args, userInitiated); + targetAsUIElement3D?.RaiseEvent(args, userInitiated); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/FocusManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/FocusManager.cs index 52f4c062632..e4b1cb9a4e8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/FocusManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/FocusManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -208,10 +208,7 @@ private static void OnFocusedElementChanged(DependencyObject d, DependencyProper DependencyObject oldVisual = (DependencyObject)e.OldValue; DependencyObject newVisual = (DependencyObject)e.NewValue; - if (oldVisual != null) - { - oldVisual.ClearValue(UIElement.IsFocusedPropertyKey); - } + oldVisual?.ClearValue(UIElement.IsFocusedPropertyKey); if (newVisual != null) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputMethod.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputMethod.cs index 5fecd80ac86..4699578f65b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputMethod.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputMethod.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1469,8 +1469,7 @@ private void UninitializeCompartmentEventSink() compartment = TextServicesCompartmentContext.Current.GetThreadCompartment(iminfo.Guid); else if (iminfo.Scope == CompartmentScope.Global) compartment = TextServicesCompartmentContext.Current.GetGlobalCompartment(iminfo.Guid); - if (compartment != null) - compartment.UnadviseNotifySink(); + compartment?.UnadviseNotifySink(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/KeyboardDevice.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/KeyboardDevice.cs index b59ac383148..27a03c51eb1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/KeyboardDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/KeyboardDevice.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -695,10 +695,7 @@ private void PreNotifyInput(object sender, NotifyInputEventArgs e) // we are now active. _activeSource = keyboardInput.InputSource; - if(toDeactivate != null) - { - toDeactivate.NotifyDeactivate(); - } + toDeactivate?.NotifyDeactivate(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Manipulation.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Manipulation.cs index 0653663e1e5..1bf5612c52e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Manipulation.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Manipulation.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -59,10 +59,7 @@ public static void StartInertia(UIElement element) ArgumentNullException.ThrowIfNull(element); ManipulationDevice device = ManipulationDevice.GetManipulationDevice(element); - if (device != null) - { - device.CompleteManipulation(/* withInertia = */ true); - } + device?.CompleteManipulation(/* withInertia = */ true); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationDevice.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationDevice.cs index c540572fbc9..19695767cc8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationDevice.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -126,10 +126,7 @@ private void RemoveManipulationDevice() RemoveAllManipulators(); - if (_manipulationDevices != null) - { - _manipulationDevices.Remove(_target); - } + _manipulationDevices?.Remove(_target); } private void RemoveAllManipulators() @@ -168,10 +165,7 @@ internal void RemoveManipulator(IManipulator manipulator) VerifyAccess(); manipulator.Updated -= OnManipulatorUpdated; - if (_manipulators != null) - { - _manipulators.Remove(manipulator); - } + _manipulators?.Remove(manipulator); // Removing a manipulator counts as an update OnManipulatorUpdated(manipulator, EventArgs.Empty); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationLogic.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationLogic.cs index a40f8ee8e15..578fe676e6c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationLogic.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationLogic.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -505,10 +505,7 @@ private static ManipulationPivot2D ConvertPivot(ManipulationPivot pivot) internal void SetManipulationParameters(ManipulationParameters2D parameter) { - if (_manipulationProcessor != null) - { - _manipulationProcessor.SetParameters(parameter); - } + _manipulationProcessor?.SetParameters(parameter); } private void UpdateManipulators(ICollection updatedManipulators) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/MouseDevice.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/MouseDevice.cs index f1945486638..48f3644ca2b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/MouseDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/MouseDevice.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1423,10 +1423,7 @@ private void PreNotifyInput(object sender, NotifyInputEventArgs e) // All mouse information is now restricted to this presentation source. _inputSource = rawMouseInputReport.InputSource; - if (toDeactivate != null) - { - toDeactivate.NotifyDeactivate(); - } + toDeactivate?.NotifyDeactivate(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/DynamicRenderer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/DynamicRenderer.cs index adc7db49a73..8006cc5861a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/DynamicRenderer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/DynamicRenderer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -519,47 +519,44 @@ void RemoveDynamicRendererVisualAndNotifyWhenDone(StrokeInfo si) if (si != null) { DynamicRendererThreadManager renderingThread = _renderingThread; // Keep it alive - if (renderingThread != null) + // We are being called by the main UI thread, so marshal over to + // the inking thread before cleaning up the stroke visual. + renderingThread?.ThreadDispatcher.BeginInvoke(DispatcherPriority.Send, + (DispatcherOperationCallback)delegate (object unused) { - // We are being called by the main UI thread, so marshal over to - // the inking thread before cleaning up the stroke visual. - renderingThread.ThreadDispatcher.BeginInvoke(DispatcherPriority.Send, - (DispatcherOperationCallback)delegate(object unused) + if (si.StrokeRTICV != null) { - if (si.StrokeRTICV != null) + // Now wait till this is rendered and then notify UI thread. + if (_onDRThreadRenderComplete == null) { - // Now wait till this is rendered and then notify UI thread. - if (_onDRThreadRenderComplete == null) - { - _onDRThreadRenderComplete = new EventHandler(OnDRThreadRenderComplete); - } + _onDRThreadRenderComplete = new EventHandler(OnDRThreadRenderComplete); + } - // Add to list to transact. - _renderCompleteDRThreadStrokeInfoList.Enqueue(si); - - // See if we are already waiting for a removed stroke to be rendered. - // If we aren't then remove visuals and wait for it to be rendered. - // Otherwise we'll do the work when the current stroke has been removed. - if (!_waitingForDRThreadRenderComplete) - { - ((ContainerVisual)si.StrokeHV.VisualTarget.RootVisual).Children.Remove(si.StrokeRTICV); - si.StrokeRTICV = null; + // Add to list to transact. + _renderCompleteDRThreadStrokeInfoList.Enqueue(si); - // hook up render complete notification for one time then unhook. - MediaContext.From(renderingThread.ThreadDispatcher).RenderComplete += _onDRThreadRenderComplete; - _waitingForDRThreadRenderComplete = true; - } - } - else + // See if we are already waiting for a removed stroke to be rendered. + // If we aren't then remove visuals and wait for it to be rendered. + // Otherwise we'll do the work when the current stroke has been removed. + if (!_waitingForDRThreadRenderComplete) { - // Nothing to transition so just say we're done! - NotifyAppOfDRThreadRenderComplete(si); + ((ContainerVisual)si.StrokeHV.VisualTarget.RootVisual).Children.Remove(si.StrokeRTICV); + si.StrokeRTICV = null; + + // hook up render complete notification for one time then unhook. + MediaContext.From(renderingThread.ThreadDispatcher).RenderComplete += _onDRThreadRenderComplete; + _waitingForDRThreadRenderComplete = true; } - - return null; - }, - null); - } + } + else + { + // Nothing to transition so just say we're done! + NotifyAppOfDRThreadRenderComplete(si); + } + + return null; + }, + null); } } @@ -567,35 +564,32 @@ void RemoveDynamicRendererVisualAndNotifyWhenDone(StrokeInfo si) private void NotifyAppOfDRThreadRenderComplete(StrokeInfo si) { Dispatcher dispatcher = _applicationDispatcher; - if (dispatcher != null) + // We are being called by the inking thread, so marshal over to + // the UI thread before handling the StrokeInfos that are done rendering. + dispatcher?.BeginInvoke(DispatcherPriority.Send, + (DispatcherOperationCallback)delegate (object unused) { - // We are being called by the inking thread, so marshal over to - // the UI thread before handling the StrokeInfos that are done rendering. - dispatcher.BeginInvoke(DispatcherPriority.Send, - (DispatcherOperationCallback)delegate(object unused) + // See if this is the one we are doing a full transition for. + if (si == _renderCompleteStrokeInfo) { - // See if this is the one we are doing a full transition for. - if (si == _renderCompleteStrokeInfo) + if (si.StrokeHV.Clip != null) { - if (si.StrokeHV.Clip != null) - { - si.StrokeHV.Clip = null; - NotifyOnNextRenderComplete(); - } - else - { - Debug.Assert(_waitingForRenderComplete, "We were expecting to be waiting for a RenderComplete to call our OnRenderComplete, we might never reset and get flashing strokes from here on out"); - TransitionComplete(si, dispatcher); // We're done - } + si.StrokeHV.Clip = null; + NotifyOnNextRenderComplete(); } else { + Debug.Assert(_waitingForRenderComplete, "We were expecting to be waiting for a RenderComplete to call our OnRenderComplete, we might never reset and get flashing strokes from here on out"); TransitionComplete(si, dispatcher); // We're done } - return null; - }, - null); - } + } + else + { + TransitionComplete(si, dispatcher); // We're done + } + return null; + }, + null); } @@ -749,7 +743,7 @@ protected virtual void OnDrawingAttributesReplaced() /// protected Dispatcher GetDispatcher() { - return _renderingThread != null ? _renderingThread.ThreadDispatcher : null; + return _renderingThread?.ThreadDispatcher; } ///////////////////////////////////////////////////////////////////// @@ -814,65 +808,59 @@ void RenderPackets(StylusPointCollection stylusPoints, StrokeInfo si) // Now add it to the visual tree (making sure we still have StrokeCV after // onDraw called above). - if (si.StrokeCV != null) - { - si.StrokeCV.Children.Add(visual); - } + si.StrokeCV?.Children.Add(visual); } else { DynamicRendererThreadManager renderingThread = _renderingThread; // keep it alive - Dispatcher drDispatcher = renderingThread != null ? renderingThread.ThreadDispatcher : null; + Dispatcher drDispatcher = renderingThread?.ThreadDispatcher; // Only try to render if we get a ref on the rendering thread. - if (drDispatcher != null) + // We are on a pen thread so marshal this call to our inking thread. + drDispatcher?.BeginInvoke(DispatcherPriority.Send, + (DispatcherOperationCallback)delegate (object unused) { - // We are on a pen thread so marshal this call to our inking thread. - drDispatcher.BeginInvoke(DispatcherPriority.Send, - (DispatcherOperationCallback) delegate(object unused) - { - SolidColorBrush fillBrush = si.FillBrush; + SolidColorBrush fillBrush = si.FillBrush; - // Make sure this stroke is not aborted - if (fillBrush != null) + // Make sure this stroke is not aborted + if (fillBrush != null) + { + // See if we need to create a new container visual for the stroke. + if (si.StrokeRTICV == null) { - // See if we need to create a new container visual for the stroke. - if (si.StrokeRTICV == null) - { - // Create new container visual for this stroke and add our incremental rendering visual to it. - si.StrokeRTICV = new ContainerVisual(); - - // two incrementally rendered stroke segments blend together - // at the rendering point location, thus the alpha value at those locations are higher than the set value. - // This is like you draw two strokes using static rendeer and the intersection part becomes darker. - // Set the opacity of the RootContainerVisual of the whole incremental stroke as color.A/255.0 and override - // the alpha value of the color we send to mil for rendering. - if (!si.DrawingAttributes.IsHighlighter) - { - si.StrokeRTICV.Opacity = si.Opacity; - } - ((ContainerVisual)si.StrokeHV.VisualTarget.RootVisual).Children.Add(si.StrokeRTICV); - } - - // Create new visual and render the geometry into it - DrawingVisual visual = new DrawingVisual(); - DrawingContext drawingContext = visual.RenderOpen(); - try + // Create new container visual for this stroke and add our incremental rendering visual to it. + si.StrokeRTICV = new ContainerVisual(); + + // two incrementally rendered stroke segments blend together + // at the rendering point location, thus the alpha value at those locations are higher than the set value. + // This is like you draw two strokes using static rendeer and the intersection part becomes darker. + // Set the opacity of the RootContainerVisual of the whole incremental stroke as color.A/255.0 and override + // the alpha value of the color we send to mil for rendering. + if (!si.DrawingAttributes.IsHighlighter) { - OnDraw(drawingContext, stylusPoints, strokeGeometry, fillBrush); + si.StrokeRTICV.Opacity = si.Opacity; } - finally - { - drawingContext.Close(); - } - // Add it to the visual tree - si.StrokeRTICV.Children.Add(visual); + ((ContainerVisual)si.StrokeHV.VisualTarget.RootVisual).Children.Add(si.StrokeRTICV); } - - return null; - }, - null); - } + + // Create new visual and render the geometry into it + DrawingVisual visual = new DrawingVisual(); + DrawingContext drawingContext = visual.RenderOpen(); + try + { + OnDraw(drawingContext, stylusPoints, strokeGeometry, fillBrush); + } + finally + { + drawingContext.Close(); + } + // Add it to the visual tree + si.StrokeRTICV.Children.Add(visual); + } + + return null; + }, + null); } } } @@ -920,10 +908,7 @@ void TransitionStrokeVisuals(StrokeInfo si, bool abortStroke) // remove si visuals and this si if (si.StrokeCV != null) { - if (_mainRawInkContainerVisual != null) - { - _mainRawInkContainerVisual.Children.Remove(si.StrokeCV); - } + _mainRawInkContainerVisual?.Children.Remove(si.StrokeCV); si.StrokeCV = null; } @@ -977,8 +962,7 @@ private DynamicRendererHostVisual GetCurrentHostVisual() } else { - HostVisual transitioningHostVisual = _renderCompleteStrokeInfo != null ? - _renderCompleteStrokeInfo.StrokeHV : null; + HostVisual transitioningHostVisual = _renderCompleteStrokeInfo?.StrokeHV; if (_currentHostVisual.InUse) { @@ -1150,11 +1134,9 @@ private void DestroyRealTimeVisuals() _renderCompleteStrokeInfo = null; DynamicRendererThreadManager renderingThread = _renderingThread; // keep ref to keep it alive in this routine - Dispatcher drDispatcher = renderingThread != null ? renderingThread.ThreadDispatcher : null; + Dispatcher drDispatcher = renderingThread?.ThreadDispatcher; - if (drDispatcher != null) - { - drDispatcher.BeginInvoke(DispatcherPriority.Send, + drDispatcher?.BeginInvoke(DispatcherPriority.Send, (DispatcherOperationCallback)delegate(object unused) { _renderCompleteDRThreadStrokeInfoList.Clear(); @@ -1170,7 +1152,6 @@ private void DestroyRealTimeVisuals() return null; }, null); - } // Make sure to free up inking thread ref to ensure thread shuts down properly. _renderingThread = null; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusLogic.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusLogic.cs index 3d6abd836dc..1883308f46c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusLogic.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusLogic.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -359,14 +359,8 @@ protected void ReadSystemConfig() } finally { - if (stylusKey != null) - { - stylusKey.Close(); - } - if (touchKey != null) - { - touchKey.Close(); - } + stylusKey?.Close(); + touchKey?.Close(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPlugin.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPlugin.cs index 3ad0147e154..fb4ed2c8a18 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPlugin.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPlugin.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -190,7 +190,7 @@ public UIElement Element { get { - return (_pic != null) ? _pic.Element : null; + return _pic?.Element; } } @@ -219,10 +219,7 @@ public bool Enabled set // on Dispatcher { // Verify we are on the proper thread. - if (_pic != null) - { - _pic.Element.VerifyAccess(); - } + _pic?.Element.VerifyAccess(); if (value != __enabled) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTouchDeviceBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTouchDeviceBase.cs index 59851be31cc..e850f3ea286 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTouchDeviceBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTouchDeviceBase.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -123,7 +123,7 @@ private void GetRootTransforms(IInputElement relativeTo, out GeneralTransform el if (containingVisual != null) { PresentationSource relativePresentationSource = PresentationSource.CriticalFromVisual(containingVisual); - Visual rootVisual = (relativePresentationSource != null) ? relativePresentationSource.RootVisual : null; + Visual rootVisual = relativePresentationSource?.RootVisual; Visual containingVisual2D = VisualTreeHelper.GetContainingVisual2D(containingVisual); if ((rootVisual != null) && (containingVisual2D != null)) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerStylusPlugInManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerStylusPlugInManager.cs index 639689727ce..af931113281 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerStylusPlugInManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerStylusPlugInManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -243,7 +243,7 @@ internal void VerifyStylusPlugInCollectionTarget(RawStylusInputReport rawStylusI RawStylusInput originalRSI = rawStylusInputReport.RawStylusInput; // See if we have a plugin for the target of this input. StylusPlugInCollection targetPIC = null; - StylusPlugInCollection targetRtiPIC = (originalRSI != null) ? originalRSI.Target : null; + StylusPlugInCollection targetRtiPIC = originalRSI?.Target; bool updateEventPoints = false; // Make sure we use UIElement for target if non NULL and hit ContentElement. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenThread.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenThread.cs index b05f60eb30e..868aac6921e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenThread.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenThread.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -39,10 +39,7 @@ internal void Dispose() void DisposeHelper() { // NOTE: PenThreadWorker deals with already being disposed logic. - if (_penThreadWorker != null) - { - _penThreadWorker.Dispose(); - } + _penThreadWorker?.Dispose(); GC.KeepAlive(this); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs index 3cdf049bcde..0fd8d879563 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -2642,7 +2642,7 @@ private void VerifyStylusPlugInCollectionTarget(RawStylusInputReport rawStylusIn RawStylusInput originalRSI = rawStylusInputReport.RawStylusInput; // See if we have a plugin for the target of this input. StylusPlugInCollection targetPIC = null; - StylusPlugInCollection targetRtiPIC = (originalRSI != null) ? originalRSI.Target : null; + StylusPlugInCollection targetRtiPIC = originalRSI?.Target; bool updateEventPoints = false; // Make sure we use UIElement for target if non NULL and hit ContentElement. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusDevice.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusDevice.cs index c038972f610..86e10dc6748 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusDevice.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -246,10 +246,7 @@ internal override bool Capture(IInputElement element, CaptureMode captureMode) throw new InvalidOperationException(SR.Format(SR.Invalid_IInputElement, doStylusCapture.GetType())); } - if (doStylusCapture != null) - { - doStylusCapture.VerifyAccess(); - } + doStylusCapture?.VerifyAccess(); bool success = false; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusPlugInCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusPlugInCollection.cs index 05807bbfd69..204654ebdd6 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusPlugInCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusPlugInCollection.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -39,7 +39,7 @@ internal override object SyncRoot { get { - return _penContexts != null ? _penContexts.SyncRoot : null; + return _penContexts?.SyncRoot; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusTouchDevice.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusTouchDevice.cs index 4d88a6de666..838cd576c42 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusTouchDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusTouchDevice.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -98,10 +98,7 @@ protected override void OnManipulationEnded(bool cancel) // rest of this touch cycle. PromotingToOther = false; } - if (_storedStagingAreaItems != null) - { - _storedStagingAreaItems.Clear(); - } + _storedStagingAreaItems?.Clear(); } /// @@ -129,10 +126,7 @@ protected override void OnActivateImpl() protected override void OnDeactivateImpl() { - if (_storedStagingAreaItems != null) - { - _storedStagingAreaItems.Clear(); - } + _storedStagingAreaItems?.Clear(); if (ActiveDeviceCount == 0) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispTabletDevice.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispTabletDevice.cs index 3c9e40fe00e..625caae6991 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispTabletDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispTabletDevice.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -346,10 +346,7 @@ internal void DisposeOrDeferDisposal() StylusDeviceCollection styluses = _stylusDeviceCollection; _stylusDeviceCollection = null; - if (styluses != null) - { - styluses.Dispose(); - } + styluses?.Dispose(); _penThread = null; _isDisposalPending = false; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextServicesContext.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextServicesContext.cs index b814f4dea41..df58c08ac2e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextServicesContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextServicesContext.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -325,10 +325,7 @@ private void SetFocusOnDim(UnsafeNativeMethods.ITfDocumentMgr dim) { UnsafeNativeMethods.ITfThreadMgr threadmgr = ThreadManager; - if (threadmgr != null) - { - threadmgr.SetFocus(dim); - } + threadmgr?.SetFocus(dim); } // Start the transitory extestion for Cicero Level1/Level2 composition window support. @@ -371,11 +368,8 @@ private void StopTransitoryExtension() { UnsafeNativeMethods.ITfSource source; source = _defaultTextStore.DocumentManager as UnsafeNativeMethods.ITfSource; - if (source != null) - { - // DocumentManager only supports ITfSource on Longhorn, XP does not support it - source.UnadviseSink(_defaultTextStore.TransitoryExtensionSinkCookie); - } + // DocumentManager only supports ITfSource on Longhorn, XP does not support it + source?.UnadviseSink(_defaultTextStore.TransitoryExtensionSinkCookie); _defaultTextStore.TransitoryExtensionSinkCookie = UnsafeNativeMethods.TF_INVALID_COOKIE; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TouchDevice.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TouchDevice.cs index cf7fdd99e84..fdb8aea3e67 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TouchDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TouchDevice.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1130,10 +1130,7 @@ private static void AddActiveDevice(TouchDevice device) private static void RemoveActiveDevice(TouchDevice device) { - if (_activeDevices != null) - { - _activeDevices.Remove(device); - } + _activeDevices?.Remove(device); } internal static TouchPointCollection GetTouchPoints(IInputElement relativeTo) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndMouseInputProvider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndMouseInputProvider.cs index 32fbbb48f1f..22ba3eca42e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndMouseInputProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndMouseInputProvider.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -293,11 +293,8 @@ int IMouseInputProvider.GetIntermediatePoints(IInputElement relativeTo, Point[] // Translate the point from the root to the visual. GeneralTransform gDown = inputSource.RootVisual.TransformToDescendant(VisualTreeHelper.GetContainingVisual2D(containingVisual)); - if (gDown != null) - { - // should we throw if the point could not be transformed? - gDown.TryTransform(currentPosition, out currentPosition); - } + // should we throw if the point could not be transformed? + gDown?.TryTransform(currentPosition, out currentPosition); points[cpt++] = currentPosition; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs index 7e0190fada4..87b755354af 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1427,10 +1427,7 @@ internal static AutomationPeer EnsureAutomationPeer(Visual root, IntPtr handle) peer = UIElementAutomationPeer.GetRootAutomationPeer(root, handle); } - if (peer != null) - { - peer.AddToAutomationEventList(); - } + peer?.AddToAutomationEventList(); return peer; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/LayoutManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/LayoutManager.cs index d6e29362957..2a13ba21550 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/LayoutManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/LayoutManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -561,8 +561,7 @@ internal override void invalidate(UIElement e) private static object UpdateLayoutCallback(object arg) { ContextLayoutManager ContextLayoutManager = arg as ContextLayoutManager; - if(ContextLayoutManager != null) - ContextLayoutManager.UpdateLayout(); + ContextLayoutManager?.UpdateLayout(); return null; } @@ -999,8 +998,7 @@ private Request _getNewRequest(UIElement e) } catch(System.OutOfMemoryException) { - if(lm != null) - lm.setForceLayout(e); + lm?.setForceLayout(e); throw; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Animatable.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Animatable.cs index 36f021cefcd..1a648d53f21 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Animatable.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Animatable.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -76,10 +76,7 @@ internal virtual void AddRefOnChannelAnimations(DUCE.Channel channel) DUCE.IResource storage = storageObject as DUCE.IResource; - if (storage != null) - { - storage.AddRefOnChannel(channel); - } + storage?.AddRefOnChannel(channel); } } } @@ -101,10 +98,7 @@ internal virtual void ReleaseOnChannelAnimations(DUCE.Channel channel) DUCE.IResource storage = storageObject as DUCE.IResource; - if (storage != null) - { - storage.ReleaseOnChannel(channel); - } + storage?.ReleaseOnChannel(channel); } } } @@ -162,18 +156,12 @@ internal static DependencyProperty RegisterProperty( // overloads. internal void AddRefResource(DUCE.IResource resource, DUCE.Channel channel) { - if (resource != null) - { - resource.AddRefOnChannel(channel); - } + resource?.AddRefOnChannel(channel); } internal void ReleaseResource(DUCE.IResource resource, DUCE.Channel channel) { - if (resource != null) - { - resource.ReleaseOnChannel(channel); - } + resource?.ReleaseOnChannel(channel); } #endregion LocalProperty/CachedValue stuff diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/AnimationStorage.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/AnimationStorage.cs index 5cf683661ae..ed5af04d773 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/AnimationStorage.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/AnimationStorage.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -211,10 +211,7 @@ internal void WritePostscript() // newly animated property will be passed across to the UCE. Animatable a = d as Animatable; - if (a != null) - { - a.RegisterForAsyncUpdateResource(); - } + a?.RegisterForAsyncUpdateResource(); // If this AnimationStorage is a resource, add it to the // channel now. @@ -282,10 +279,7 @@ internal void WritePostscript() // across to the UCE. Animatable a = d as Animatable; - if (a != null) - { - a.RegisterForAsyncUpdateResource(); - } + a?.RegisterForAsyncUpdateResource(); animatedPropertyMap[_dependencyProperty.GlobalIndex] = DependencyProperty.UnsetValue; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Clock.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Clock.cs index ada8d261b2a..3cf8fb0845e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Clock.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Clock.cs @@ -3703,13 +3703,10 @@ private void NotifyNewEarliestFutureActivity() current = current._parent; } - if (_timeManager != null) - { - // If we get here from within a Tick, this will force MediaContext to perform another subsequent Tick - // on the TimeManager. This will apply the requested interactive operations, so their results will - // immediately become visible. - _timeManager.SetDirty(); - } + // If we get here from within a Tick, this will force MediaContext to perform another subsequent Tick + // on the TimeManager. This will apply the requested interactive operations, so their results will + // immediately become visible. + _timeManager?.SetDirty(); } @@ -3828,10 +3825,7 @@ private void UpdateNeedsTicksWhenActive() // This wrapper is invoked anytime we invalidate the _beginTime private void UpdateSyncBeginTime() { - if (_syncData != null) - { - _syncData.UpdateClockBeginTime(); - } + _syncData?.UpdateClockBeginTime(); } private void VerifyNeedsTicksWhenActive() @@ -4308,10 +4302,7 @@ internal void RootBuildInfoRecursive(System.Text.StringBuilder builder) { Clock child = (Clock)children[index].Target; - if (child != null) - { - child.BuildInfoRecursive(builder, 1); - } + child?.BuildInfoRecursive(builder, 1); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Animatable.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Animatable.cs index d317f765f21..396f2dae7b2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Animatable.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Animatable.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -215,10 +215,7 @@ internal sealed override void EvaluateAnimatedValueCore( { AnimationStorage storage = AnimationStorage.GetStorage(this, dp); - if (storage != null) - { - storage.EvaluateAnimatedValue(metadata, ref entry); - } + storage?.EvaluateAnimatedValue(metadata, ref entry); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Subtree.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Subtree.cs index 797eafbe8bc..c9dd4f76cb8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Subtree.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Subtree.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -96,7 +96,7 @@ public bool MoveNext() // The next clock is possibly the first child of the current clock ClockGroup currentClockGroup = _currentClock as ClockGroup; - Clock nextClock = (currentClockGroup == null) ? null : currentClockGroup.FirstChild; + Clock nextClock = currentClockGroup?.FirstChild; // Skip the children if explicitly asked to do so, or if there aren't any if (((_flags & SubtreeFlag.SkipSubtree) != 0) || (nextClock == null)) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/TimeManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/TimeManager.cs index 5d6da5e629e..f15597eedd3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/TimeManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/TimeManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -616,10 +616,7 @@ private void RaiseEnqueuedEvents() WeakReference instance = _eventQueue.Dequeue(); Clock clock = (Clock)instance.Target; - if (clock != null) - { - clock.RaiseAccumulatedEvents(); - } + clock?.RaiseAccumulatedEvents(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/TimelineClockCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/TimelineClockCollection.cs index 820d9079a42..ae9f6421eb7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/TimelineClockCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/TimelineClockCollection.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -125,11 +125,8 @@ public void CopyTo(Clock[] array, int index) { List list = clockGroup.InternalChildren; - if (list != null) - { - // Get free parameter validation from Array.Copy - list.CopyTo(array, index); - } + // Get free parameter validation from Array.Copy + list?.CopyTo(array, index); } // Need to perform parameter validation in the list == null case diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/BitmapCacheBrush.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/BitmapCacheBrush.cs index 0aec82adb5f..d93bda1b07c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/BitmapCacheBrush.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/BitmapCacheBrush.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -149,18 +149,12 @@ void ICyclicBrush.RenderForCyclicBrush(DUCE.Channel channel, bool skipChannelChe // to be specialized for Visual which doesn't implement DUCE.IResource internal void AddRefResource(Visual visual, DUCE.Channel channel) { - if (visual != null) - { - visual.AddRefOnChannelForCyclicBrush(this, channel); - } + visual?.AddRefOnChannelForCyclicBrush(this, channel); } internal void ReleaseResource(Visual visual, DUCE.Channel channel) { - if (visual != null) - { - visual.ReleaseOnChannelForCyclicBrush(this, channel); - } + visual?.ReleaseOnChannelForCyclicBrush(this, channel); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/CharacterMetricsDictionary.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/CharacterMetricsDictionary.cs index 82306df2896..153700303a9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/CharacterMetricsDictionary.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/CharacterMetricsDictionary.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -330,7 +330,7 @@ void SC.IDictionary.Remove(object key) internal CharacterMetrics[] GetPage(int i) { - return (_pageTable != null) ? _pageTable[i] : null; + return _pageTable?[i]; } private CharacterMetrics[] GetPageFromUnicodeScalar(int unicodeScalar) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DrawingVisual.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DrawingVisual.cs index 6fee311c133..796c3fe5742 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DrawingVisual.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DrawingVisual.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -109,11 +109,8 @@ internal override void RenderClose(IDrawingContent newContent) // Prepare the new content. // - if (newContent != null) - { - // Propagate notification handlers. - newContent.PropagateChangedHandler(ContentsChangedHandler, true /* adding */); - } + // Propagate notification handlers. + newContent?.PropagateChangedHandler(ContentsChangedHandler, true /* adding */); _content = newContent; @@ -194,10 +191,7 @@ internal void WalkContent(DrawingContextWalker walker) { VerifyAPIReadOnly(); - if (_content != null) - { - _content.WalkContent(walker); - } + _content?.WalkContent(walker); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/PixelShader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/PixelShader.cs index e8160d96afe..4240bc8ccfd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/PixelShader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/PixelShader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -98,10 +98,7 @@ private void UriSourcePropertyChangedHook(DependencyPropertyChangedEventArgs e) } finally { - if (stream != null) - { - stream.Dispose(); - } + stream?.Dispose(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs index 9aa10b75c8a..42b177e5390 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -265,10 +265,7 @@ protected static PropertyChangedCallback PixelShaderConstantCallback(int floatRe (obj, args) => { ShaderEffect eff = obj as ShaderEffect; - if (eff != null) - { - eff.UpdateShaderConstant(args.Property, args.NewValue, floatRegisterIndex); - } + eff?.UpdateShaderConstant(args.Property, args.NewValue, floatRegisterIndex); }; } @@ -767,10 +764,7 @@ internal override DUCE.ResourceHandle AddRefOnChannelCore(DUCE.Channel channel) SamplerData ss = ssn.Value; DUCE.IResource brush = ss._brush as DUCE.IResource; - if (brush != null) - { - brush.AddRefOnChannel(channel); - } + brush?.AddRefOnChannel(channel); } } } @@ -807,10 +801,7 @@ internal override void ReleaseOnChannelCore(DUCE.Channel channel) SamplerData ss = ssn.Value; DUCE.IResource brush = ss._brush as DUCE.IResource; - if (brush != null) - { - brush.ReleaseOnChannel(channel); - } + brush?.ReleaseOnChannel(channel); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs index 53ae8f0a493..8ce83ee1655 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1068,8 +1068,7 @@ public bool MoveNext() TextWrapping currentWrap = _that._defaultParaProps.TextWrapping; _that._defaultParaProps.SetTextWrapping(TextWrapping.NoWrap); - if (currentLineBreak != null) - currentLineBreak.Dispose(); + currentLineBreak?.Dispose(); _currentLine.Dispose(); _currentLine = FormatLine( @@ -1088,8 +1087,7 @@ public bool MoveNext() _previousHeight = _currentLine.Height; _previousLength = _currentLine.Length; - if (_previousLineBreak != null) - _previousLineBreak.Dispose(); + _previousLineBreak?.Dispose(); _previousLineBreak = currentLineBreak; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/BitmapCacheBrush.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/BitmapCacheBrush.cs index 6745d75cea1..61e8283d719 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/BitmapCacheBrush.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/BitmapCacheBrush.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -368,7 +368,7 @@ internal override DUCE.ResourceHandle AddRefOnChannelCore(DUCE.Channel channel) BitmapCache vBitmapCache = BitmapCache; if (vBitmapCache != null) ((DUCE.IResource)vBitmapCache).AddRefOnChannel(channel); Visual vInternalTarget = InternalTarget; - if (vInternalTarget != null) vInternalTarget.AddRefOnChannelForCyclicBrush(this, channel); + vInternalTarget?.AddRefOnChannelForCyclicBrush(this, channel); AddRefOnChannelAnimations(channel); @@ -390,7 +390,7 @@ internal override void ReleaseOnChannelCore(DUCE.Channel channel) BitmapCache vBitmapCache = BitmapCache; if (vBitmapCache != null) ((DUCE.IResource)vBitmapCache).ReleaseOnChannel(channel); Visual vInternalTarget = InternalTarget; - if (vInternalTarget != null) vInternalTarget.ReleaseOnChannelForCyclicBrush(this, channel); + vInternalTarget?.ReleaseOnChannelForCyclicBrush(this, channel); ReleaseOnChannelAnimations(channel); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/DrawingContextWalker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/DrawingContextWalker.cs index ea4e7e9d25f..b8794d77574 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/DrawingContextWalker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/DrawingContextWalker.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -329,10 +329,7 @@ public override void DrawGlyphRun( public override void DrawDrawing( Drawing drawing) { - if (drawing != null) - { - drawing.WalkCurrentValue(this); - } + drawing?.WalkCurrentValue(this); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/DrawingGroup.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/DrawingGroup.cs index cc25b3c9732..725e4e0d5b3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/DrawingGroup.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/DrawingGroup.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -686,10 +686,7 @@ private void ChildrenItemInserted(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource addResource = item as DUCE.IResource; - if (addResource != null) - { - addResource.AddRefOnChannel(channel); - } + addResource?.AddRefOnChannel(channel); UpdateResource(channel, true /* skip on channel check */); } @@ -716,10 +713,7 @@ private void ChildrenItemRemoved(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource releaseResource = item as DUCE.IResource; - if (releaseResource != null) - { - releaseResource.ReleaseOnChannel(channel); - } + releaseResource?.ReleaseOnChannel(channel); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/GeometryGroup.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/GeometryGroup.cs index 632bf429e87..a71079a523c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/GeometryGroup.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/GeometryGroup.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -354,10 +354,7 @@ private void ChildrenItemInserted(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource addResource = item as DUCE.IResource; - if (addResource != null) - { - addResource.AddRefOnChannel(channel); - } + addResource?.AddRefOnChannel(channel); UpdateResource(channel, true /* skip on channel check */); } @@ -384,10 +381,7 @@ private void ChildrenItemRemoved(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource releaseResource = item as DUCE.IResource; - if (releaseResource != null) - { - releaseResource.ReleaseOnChannel(channel); - } + releaseResource?.ReleaseOnChannel(channel); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/TransformGroup.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/TransformGroup.cs index c532ff43c0e..514f36da494 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/TransformGroup.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/TransformGroup.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -309,10 +309,7 @@ private void ChildrenItemInserted(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource addResource = item as DUCE.IResource; - if (addResource != null) - { - addResource.AddRefOnChannel(channel); - } + addResource?.AddRefOnChannel(channel); UpdateResource(channel, true /* skip on channel check */); } @@ -339,10 +336,7 @@ private void ChildrenItemRemoved(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource releaseResource = item as DUCE.IResource; - if (releaseResource != null) - { - releaseResource.ReleaseOnChannel(channel); - } + releaseResource?.ReleaseOnChannel(channel); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/VisualBrush.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/VisualBrush.cs index 8129e403d0d..911ce978d5a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/VisualBrush.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/VisualBrush.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -278,7 +278,7 @@ internal override DUCE.ResourceHandle AddRefOnChannelCore(DUCE.Channel channel) Transform vRelativeTransform = RelativeTransform; if (vRelativeTransform != null) ((DUCE.IResource)vRelativeTransform).AddRefOnChannel(channel); Visual vVisual = Visual; - if (vVisual != null) vVisual.AddRefOnChannelForCyclicBrush(this, channel); + vVisual?.AddRefOnChannelForCyclicBrush(this, channel); AddRefOnChannelAnimations(channel); @@ -298,7 +298,7 @@ internal override void ReleaseOnChannelCore(DUCE.Channel channel) Transform vRelativeTransform = RelativeTransform; if (vRelativeTransform != null) ((DUCE.IResource)vRelativeTransform).ReleaseOnChannel(channel); Visual vVisual = Visual; - if (vVisual != null) vVisual.ReleaseOnChannelForCyclicBrush(this, channel); + vVisual?.ReleaseOnChannelForCyclicBrush(this, channel); ReleaseOnChannelAnimations(channel); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Geometry.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Geometry.cs index 1a1e8ad9597..8c394643b16 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Geometry.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Geometry.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -398,10 +398,7 @@ internal virtual bool ContainsInternal(Pen pen, Point hitPoint, double tolerance double[] dashArray = null; // If we have a pen, populate the CMD struct - if (pen != null) - { - pen.GetBasicPenData(&penData, out dashArray); - } + pen?.GetBasicPenData(&penData, out dashArray); fixed (byte* pbPathData = pathData.SerializedData) { @@ -451,10 +448,7 @@ internal unsafe bool ContainsInternal(Pen pen, Point hitPoint, double tolerance, MIL_PEN_DATA penData; double[] dashArray = null; - if (pen != null) - { - pen.GetBasicPenData(&penData, out dashArray); - } + pen?.GetBasicPenData(&penData, out dashArray); fixed (double *dashArrayFixed = dashArray) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs index ca0edcb0cfb..bd3dc40ba70 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -211,10 +211,7 @@ SafeFileHandle safeFilehandle // of BitmapDecoder (such as JpegBitmapDecoder), those subclasses are constructed in // CreateFromUriOrStream, which also gets uriStream from SetupDecoderFromUriOrStream. // - if (_uriStream != null) - { - _uriStream.Close(); - } + _uriStream?.Close(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapFrameDecode.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapFrameDecode.cs index 1527655d7a9..5880f45859e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapFrameDecode.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapFrameDecode.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -280,10 +280,7 @@ public override InPlaceBitmapMetadataWriter CreateInPlaceBitmapMetadataWriter() { ReadPreamble(); - if (_decoder != null) - { - _decoder.CheckOriginalWritable(); - } + _decoder?.CheckOriginalWritable(); // Demand Site Of Origin on the URI before usage of metadata. CheckIfSiteOfOrigin(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapMetadata.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapMetadata.cs index ae8f0353562..29d66d688f7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapMetadata.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapMetadata.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -309,10 +309,7 @@ out pIMetadataWriter } finally { - if (pIMetadataReader != null) - { - pIMetadataReader.Dispose(); - } + pIMetadataReader?.Dispose(); if (pIMetadataWriter != IntPtr.Zero) { #pragma warning suppress 6031 // Return value ignored on purpose. @@ -1117,10 +1114,7 @@ ref propVar { BitmapMetadata metadata = objValue as BitmapMetadata; - if (metadata != null) - { - metadata.Freeze(); - } + metadata?.Freeze(); } return objValue; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapSource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapSource.cs index 99908947ab1..3f0d002685b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapSource.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapSource.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -894,8 +894,7 @@ internal virtual BitmapSourceSafeMILHandle DUCECompatiblePtr } finally { - if (pIWicConverter != null) - pIWicConverter.Close(); + pIWicConverter?.Close(); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/CroppedBitmap.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/CroppedBitmap.cs index f7721e4775d..f571cd9d956 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/CroppedBitmap.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/CroppedBitmap.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -124,10 +124,7 @@ internal override void FinalizeCreation() } finally { - if (wicClipper != null) - { - wicClipper.Close(); - } + wicClipper?.Close(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/FormatConvertedBitmap.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/FormatConvertedBitmap.cs index 5a4670ff811..cd87e7c2c4e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/FormatConvertedBitmap.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/FormatConvertedBitmap.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -139,10 +139,7 @@ internal override void FinalizeCreation() } finally { - if (wicFormatter != null) - { - wicFormatter.Close(); - } + wicFormatter?.Close(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs index 00e222801f5..6a2e7898013 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -348,10 +348,7 @@ private object InvalidateRenderMode(object dontCare) { HwndTarget hwndTarget = target as HwndTarget; - if (hwndTarget != null) - { - hwndTarget.InvalidateRenderMode(); - } + hwndTarget?.InvalidateRenderMode(); } return null; @@ -2068,10 +2065,7 @@ private void Render(ICompositionTarget resizedCompositionTarget) // will wait until we have presented before committing this channel // - if (Channel != null) - { - Channel.CloseBatch(); - } + Channel?.CloseBatch(); _needToCommitChannel = true; _commitPendingAfterRender = true; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PathGeometry.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PathGeometry.cs index 8e6ec842f1a..6b67e93ee55 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PathGeometry.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PathGeometry.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -663,10 +663,7 @@ public void Clear() { PathFigureCollection figures = Figures; - if (figures != null) - { - figures.Clear(); - } + figures?.Clear(); } #endregion @@ -758,10 +755,7 @@ internal static MilRectD GetPathBoundsAsRB( double[] dashArray = null; // If we have a pen, populate the CMD struct - if (pen != null) - { - pen.GetBasicPenData(&penData, out dashArray); - } + pen?.GetBasicPenData(&penData, out dashArray); MilMatrix3x2D worldMatrix3X2 = CompositionResourceManager.MatrixToMilMatrix3x2D(ref worldMatrix); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Pen.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Pen.cs index 3141dd7c848..a151c228529 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Pen.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Pen.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -116,10 +116,7 @@ internal unsafe void GetBasicPenData(MIL_PEN_DATA* pData, out double[] dashArray pData->MiterLimit = MiterLimit; } - if (DashStyle != null) - { - DashStyle.GetDashData(pData, out dashArray); - } + DashStyle?.GetDashData(pData, out dashArray); } internal bool DoesNotContainGaps diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/RenderData.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/RenderData.cs index 3a0472c0c9d..9742ee144ce 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/RenderData.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/RenderData.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -341,10 +341,7 @@ DUCE.ResourceHandle DUCE.IResource.AddRefOnChannel(DUCE.Channel channel) { DUCE.IResource resource = _dependentResources[i] as DUCE.IResource; - if (resource != null) - { - resource.AddRefOnChannel(channel); - } + resource?.AddRefOnChannel(channel); } UpdateResource(channel); @@ -369,10 +366,7 @@ void DUCE.IResource.ReleaseOnChannel(DUCE.Channel channel) { DUCE.IResource resource = _dependentResources[i] as DUCE.IResource; - if (resource != null) - { - resource.ReleaseOnChannel(channel); - } + resource?.ReleaseOnChannel(channel); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/SafeMILHandle.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/SafeMILHandle.cs index 9df128f29d1..294aa587321 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/SafeMILHandle.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/SafeMILHandle.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -39,10 +39,7 @@ internal SafeMILHandle(IntPtr handle) : base(true) /// internal void UpdateEstimatedSize(long estimatedSize) { - if (_gcPressure != null) - { - _gcPressure.Release(); - } + _gcPressure?.Release(); // // estimatedSize may be 0 for small images with fewer than 8 bits per pixel, @@ -59,10 +56,7 @@ internal void UpdateEstimatedSize(long estimatedSize) internal void CopyMemoryPressure(SafeMILHandle original) { _gcPressure = original._gcPressure; - if (_gcPressure != null) - { - _gcPressure.AddRef(); - } + _gcPressure?.AddRef(); } protected override bool ReleaseHandle() diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Visual.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Visual.cs index 280aee3e258..5e7b6c10033 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Visual.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Visual.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -3023,7 +3023,7 @@ protected set // To enable emulation of the legacy effects on top of the new effects pipeline, store the // bitmap effect information in our staging uncommon field: UserProvidedBitmapEffectData. - BitmapEffect oldBitmapEffect = (bed == null) ? null : bed.BitmapEffect; + BitmapEffect oldBitmapEffect = bed?.BitmapEffect; if (oldBitmapEffect == value) // If new and old value are the same, this set call can be treated as a no-op. { return; @@ -3120,7 +3120,7 @@ protected set // To enable emulation of the legacy effects on top of the new effects pipeline, store the // bitmap effect input information in our staging uncommon field: UserProvidedBitmapEffectData. - BitmapEffectInput oldBitmapEffectInput = (bed == null) ? null : bed.BitmapEffectInput; + BitmapEffectInput oldBitmapEffectInput = bed?.BitmapEffectInput; BitmapEffectInput newBitmapEffectInput = value; if (oldBitmapEffectInput == newBitmapEffectInput) // If new and old value are the same, this set call can be treated as a no-op. @@ -3161,8 +3161,8 @@ protected set internal void BitmapEffectEmulationChanged(object sender, EventArgs e) { BitmapEffectState bed = UserProvidedBitmapEffectData.GetValue(this); - BitmapEffect currentBitmapEffect = (bed == null) ? null : bed.BitmapEffect; - BitmapEffectInput currentBitmapEffectInput = (bed == null) ? null : bed.BitmapEffectInput; + BitmapEffect currentBitmapEffect = bed?.BitmapEffect; + BitmapEffectInput currentBitmapEffectInput = bed?.BitmapEffectInput; // Note that when this method is called, a legacy BitmapEffect has been set or reset on // the Visual by the user. The next step is to try to emulate the effect in case the current @@ -3254,7 +3254,7 @@ internal BitmapEffect VisualBitmapEffectInternal { BitmapEffectState bitmapEffectState = BitmapEffectStateField.GetValue(this); - BitmapEffect bitmapEffect = (bitmapEffectState == null) ? null : bitmapEffectState.BitmapEffect; + BitmapEffect bitmapEffect = bitmapEffectState?.BitmapEffect; if (bitmapEffect == value) { return; @@ -3305,7 +3305,7 @@ internal BitmapEffectInput VisualBitmapEffectInputInternal VerifyAPIReadWrite(); BitmapEffectState bitmapEffectState = BitmapEffectStateField.GetValue(this); - BitmapEffectInput bitmapEffectInput = (bitmapEffectState == null) ? null : bitmapEffectState.BitmapEffectInput; + BitmapEffectInput bitmapEffectInput = bitmapEffectState?.BitmapEffectInput; if (bitmapEffectInput == value) { return; @@ -4598,10 +4598,7 @@ internal bool TrySimpleTransformToAncestor(Visual ancestor, } // group can be null if it does not have an inverse - if (group != null) - { - group.Freeze(); - } + group?.Freeze(); // Initialize out params generalTransform = group; @@ -4971,10 +4968,7 @@ internal void RecursiveSetDpiScaleVisualFlags(DpiRecursiveChangeArgs args) for (int i = 0; i < count; i++) { Visual cv = InternalGetVisualChild(i); - if (cv != null) - { - cv.RecursiveSetDpiScaleVisualFlags(args); - } + cv?.RecursiveSetDpiScaleVisualFlags(args); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/VisualBrush.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/VisualBrush.cs index ea98a166d61..cc817be464c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/VisualBrush.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/VisualBrush.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -150,18 +150,12 @@ void ICyclicBrush.RenderForCyclicBrush(DUCE.Channel channel, bool skipChannelChe // to be specialized for Visual which doesn't implement DUCE.IResource internal void AddRefResource(Visual visual, DUCE.Channel channel) { - if (visual != null) - { - visual.AddRefOnChannelForCyclicBrush(this, channel); - } + visual?.AddRefOnChannelForCyclicBrush(this, channel); } internal void ReleaseResource(Visual visual, DUCE.Channel channel) { - if (visual != null) - { - visual.ReleaseOnChannelForCyclicBrush(this, channel); - } + visual?.ReleaseOnChannelForCyclicBrush(this, channel); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextRunCache.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextRunCache.cs index 5215be9a613..bceb21caf6e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextRunCache.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextRunCache.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -47,14 +47,11 @@ public void Change( int removal ) { - if(_imp != null) - { - _imp.Change( + _imp?.Change( textSourceCharacterIndex, addition, removal ); - } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/MaterialGroup.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/MaterialGroup.cs index 49e66c7b1f1..7313b3f9f66 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/MaterialGroup.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/MaterialGroup.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -309,10 +309,7 @@ private void ChildrenItemInserted(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource addResource = item as DUCE.IResource; - if (addResource != null) - { - addResource.AddRefOnChannel(channel); - } + addResource?.AddRefOnChannel(channel); UpdateResource(channel, true /* skip on channel check */); } @@ -339,10 +336,7 @@ private void ChildrenItemRemoved(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource releaseResource = item as DUCE.IResource; - if (releaseResource != null) - { - releaseResource.ReleaseOnChannel(channel); - } + releaseResource?.ReleaseOnChannel(channel); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Model3DGroup.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Model3DGroup.cs index b195fdb312f..375722336d9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Model3DGroup.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Model3DGroup.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -330,10 +330,7 @@ private void ChildrenItemInserted(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource addResource = item as DUCE.IResource; - if (addResource != null) - { - addResource.AddRefOnChannel(channel); - } + addResource?.AddRefOnChannel(channel); UpdateResource(channel, true /* skip on channel check */); } @@ -360,10 +357,7 @@ private void ChildrenItemRemoved(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource releaseResource = item as DUCE.IResource; - if (releaseResource != null) - { - releaseResource.ReleaseOnChannel(channel); - } + releaseResource?.ReleaseOnChannel(channel); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Transform3DGroup.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Transform3DGroup.cs index 70cecc24eae..5821ed2e081 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Transform3DGroup.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Transform3DGroup.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -309,10 +309,7 @@ private void ChildrenItemInserted(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource addResource = item as DUCE.IResource; - if (addResource != null) - { - addResource.AddRefOnChannel(channel); - } + addResource?.AddRefOnChannel(channel); UpdateResource(channel, true /* skip on channel check */); } @@ -339,10 +336,7 @@ private void ChildrenItemRemoved(object sender, object item) // We're on a channel, which means our dependents are also on the channel. DUCE.IResource releaseResource = item as DUCE.IResource; - if (releaseResource != null) - { - releaseResource.ReleaseOnChannel(channel); - } + releaseResource?.ReleaseOnChannel(channel); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Visual3D.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Visual3D.cs index e08a3343394..5f010fc7654 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Visual3D.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Visual3D.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -217,10 +217,7 @@ internal sealed override void EvaluateAnimatedValueCore( { AnimationStorage storage = AnimationStorage.GetStorage(this, dp); - if (storage != null) - { - storage.EvaluateAnimatedValue(metadata, ref entry); - } + storage?.EvaluateAnimatedValue(metadata, ref entry); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/RayHitTestParameters.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/RayHitTestParameters.cs index dd3abeb5fdd..bfebf8050b9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/RayHitTestParameters.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/RayHitTestParameters.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -186,10 +186,7 @@ internal void GetLocalLine(out Point3D origin, out Vector3D direction) internal void ClearResults() { - if (results != null) - { - results.Clear(); - } + results?.Clear(); } #endregion Internal Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport3DVisual.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport3DVisual.cs index 51ca2ee4653..b41428c75dd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport3DVisual.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport3DVisual.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -332,10 +332,7 @@ void IVisual3DContainer.AddChild(Visual3D child) child.SetParent(this); // set the inheritance context so databinding, etc... work - if (_inheritanceContextForChildren != null) - { - _inheritanceContextForChildren.ProvideSelfAsInheritanceContext(child, null); - } + _inheritanceContextForChildren?.ProvideSelfAsInheritanceContext(child, null); SetFlagsOnAllChannels(true, VisualProxyFlags.IsContentDirty); @@ -385,10 +382,7 @@ void IVisual3DContainer.RemoveChild(Visual3D child) child.SetParent(/* newParent = */ (Visual) null); // CS0121: Call is ambigious without casting null to Visual. // remove the inheritance context - if (_inheritanceContextForChildren != null) - { - _inheritanceContextForChildren.RemoveSelfAsInheritanceContext(child, null); - } + _inheritanceContextForChildren?.RemoveSelfAsInheritanceContext(child, null); // // Remove the child on all channels this visual is marshalled to. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Visual3D.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Visual3D.cs index e6a0e9966f4..e333c60cc79 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Visual3D.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Visual3D.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -166,10 +166,10 @@ private static void TransformPropertyChanged(DependencyObject d, DependencyPrope // Stop over-invalidating _bboxSubgraph // - // We currently maintain a cache of both a ModelVisual3D’s content + // We currently maintain a cache of both a ModelVisual3D’s content // and subgraph bounds. A better solution that would be both a 2D // and 3D win would be to stop invalidating _bboxSubgraph when a - // visual’s transform changes. + // visual’s transform changes. owner.RenderChanged(/* sender = */ owner, EventArgs.Empty); } @@ -1676,10 +1676,7 @@ private GeneralTransform3D InternalTransformToAncestor(Visual3D ancestor, bool i if (gAsVisual3D != null) { Transform3D transform = gAsVisual3D.Transform; - if (transform != null) - { - transform.Append(ref m); - } + transform?.Append(ref m); lastVisual3D = gAsVisual3D; g = VisualTreeHelper.GetParent(gAsVisual3D); @@ -1754,10 +1751,7 @@ private GeneralTransform3D InternalTransformToAncestor(Visual3D ancestor, bool i } } - if (finalTransform != null) - { - finalTransform.Freeze(); - } + finalTransform?.Freeze(); return finalTransform; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/MouseCaptureWithinProperty.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/MouseCaptureWithinProperty.cs index 8a151693509..752db8d226d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/MouseCaptureWithinProperty.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/MouseCaptureWithinProperty.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -37,9 +37,9 @@ internal override void FireNotifications(UIElement uie, ContentElement ce, UIEle { ce.RaiseIsMouseCaptureWithinChanged(args); } - else if (uie3D != null) + else { - uie3D.RaiseIsMouseCaptureWithinChanged(args); + uie3D?.RaiseIsMouseCaptureWithinChanged(args); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/MouseOverProperty.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/MouseOverProperty.cs index 66aca09f565..0e861064554 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/MouseOverProperty.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/MouseOverProperty.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -55,9 +55,9 @@ internal override void FireNotifications(UIElement uie, ContentElement ce, UIEle { ce.RaiseEvent(mouseEventArgs); } - else if (uie3D != null) + else { - uie3D.RaiseEvent(mouseEventArgs); + uie3D?.RaiseEvent(mouseEventArgs); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/PresentationSource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/PresentationSource.cs index df763b6cb19..3c9fe944bbf 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/PresentationSource.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/PresentationSource.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -431,36 +431,21 @@ protected void RootChanged(Visual oldRoot, Visual newRoot) } // Always set the SourceProperty on the new root. - if (newRoot != null) - { - newRoot.SetValue(RootSourceProperty, this); - } + newRoot?.SetValue(RootSourceProperty, this); UIElement oldRootUIElement = oldRoot as UIElement; UIElement newRootUIElement = newRoot as UIElement; // The IsVisible property can only be true if root visual is connected to a presentation source. // For Read-Only force-inherited properties, use a private update method. - if(oldRootUIElement != null) - { - oldRootUIElement.UpdateIsVisibleCache(); - } - if(newRootUIElement != null) - { - newRootUIElement.UpdateIsVisibleCache(); - } + oldRootUIElement?.UpdateIsVisibleCache(); + newRootUIElement?.UpdateIsVisibleCache(); // Broadcast the Unloaded event starting at the old root visual - if (oldRootUIElement != null) - { - oldRootUIElement.OnPresentationSourceChanged(false); - } + oldRootUIElement?.OnPresentationSourceChanged(false); // Broadcast the Loaded event starting at the root visual - if (newRootUIElement != null) - { - newRootUIElement.OnPresentationSourceChanged(true); - } + newRootUIElement?.OnPresentationSourceChanged(true); // To fire PresentationSourceChanged when the RootVisual changes; // rather than simulate a "parent" pointer change, we just walk the diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/ReverseInheritProperty.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/ReverseInheritProperty.cs index c433f2e51e2..27efbb9edf3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/ReverseInheritProperty.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/ReverseInheritProperty.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -261,9 +261,9 @@ private static void SetFlag(UIElement uie, ContentElement ce, UIElement3D uie3D, { ce.WriteFlag(flag, value); } - else if (uie3D != null) + else { - uie3D.WriteFlag(flag, value); + uie3D?.WriteFlag(flag, value); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/StylusCaptureWithinProperty.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/StylusCaptureWithinProperty.cs index b21dab228a7..f5e0fac8d99 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/StylusCaptureWithinProperty.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/StylusCaptureWithinProperty.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -37,9 +37,9 @@ internal override void FireNotifications(UIElement uie, ContentElement ce, UIEle { ce.RaiseIsStylusCaptureWithinChanged(args); } - else if (uie3D != null) + else { - uie3D.RaiseIsStylusCaptureWithinChanged(args); + uie3D?.RaiseIsStylusCaptureWithinChanged(args); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/StylusOverProperty.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/StylusOverProperty.cs index f3f2dfd87d8..604875848b3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/StylusOverProperty.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/StylusOverProperty.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -47,9 +47,9 @@ internal override void FireNotifications(UIElement uie, ContentElement ce, UIEle { ce.RaiseEvent(stylusEventArgs); } - else if (uie3D != null) + else { - uie3D.RaiseEvent(stylusEventArgs); + uie3D?.RaiseEvent(stylusEventArgs); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs index c5737d7694c..b99805687ae 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -699,8 +699,8 @@ public void Measure(Size availableSize) GetUIParentOrICH(out p, out ich); //only one will be returned if (p != null && !p.MeasureInProgress) //this is what differs this code from signalDesiredSizeChange() p.OnChildDesiredSizeChanged(this); - else if (ich != null) - ich.OnChildDesiredSizeChanged(this); + else + ich?.OnChildDesiredSizeChanged(this); } } } @@ -1684,9 +1684,9 @@ internal static void BuildRouteHelper(DependencyObject e, EventRoute route, Rout { contentElement.AddToEventRoute(route, args); } - else if (uiElement3D != null) + else { - uiElement3D.AddToEventRoute(route, args); + uiElement3D?.AddToEventRoute(route, args); } } else @@ -2162,7 +2162,7 @@ public DependencyObject Result { get { - return _result != null ? _result.VisualHit : null; + return _result?.VisualHit; } } @@ -3058,8 +3058,8 @@ private void signalDesiredSizeChange() if(p != null) p.OnChildDesiredSizeChanged(this); - else if(ich != null) - ich.OnChildDesiredSizeChanged(this); + else + ich?.OnChildDesiredSizeChanged(this); } private void ensureClip(Size layoutSlotSize) @@ -3171,11 +3171,8 @@ internal override void RenderClose(IDrawingContent newContent) // Prepare the new content. // - if (newContent != null) - { - // Propagate notification handlers. - newContent.PropagateChangedHandler(ContentsChangedHandler, true /* adding */); - } + // Propagate notification handlers. + newContent?.PropagateChangedHandler(ContentsChangedHandler, true /* adding */); _drawingContent = newContent; @@ -3253,10 +3250,7 @@ internal void WalkContent(DrawingContextWalker walker) { VerifyAPIReadOnly(); - if (_drawingContent != null) - { - _drawingContent.WalkContent(walker); - } + _drawingContent?.WalkContent(walker); } /// @@ -3680,8 +3674,7 @@ private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyCha //Notify Automation in case it is interested. AutomationPeer peer = uie.GetAutomationPeer(); - if(peer != null) - peer.InvalidatePeer(); + peer?.InvalidatePeer(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs index f4db8a5eca9..13c782ec4d2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -902,8 +902,7 @@ private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyCha //Notify Automation in case it is interested. AutomationPeer peer = uie.GetAutomationPeer(); - if (peer != null) - peer.InvalidatePeer(); + peer?.InvalidatePeer(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs index d5be1646d41..c0c72e078a4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -163,8 +163,7 @@ internal static PathNode BuildPathForElements(ICollection nodes) // make all the children readonly so we do not need to // lock the PathNode when getting the children - if (firstPathNode != null) - firstPathNode.FreezeChildren(); + firstPathNode?.FreezeChildren(); return firstPathNode; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AdornerPresentationContext.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AdornerPresentationContext.cs index 415930d86ae..ea2c5eae145 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AdornerPresentationContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AdornerPresentationContext.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -200,7 +200,7 @@ public override void RemoveFromHost(IAnnotationComponent component, bool reorder // now get rid of reference from presentation context of annotation component to annotation adorner AdornerPresentationContext p = component.PresentationContext as AdornerPresentationContext; - if (p != null) p.ResetInternalAnnotationAdorner(); + p?.ResetInternalAnnotationAdorner(); // finally get rid of reference from annotation component to presentation context component.PresentationContext = null; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AnnotationComponentManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AnnotationComponentManager.cs index 6496dc51145..dcc5d677caf 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AnnotationComponentManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AnnotationComponentManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -88,8 +88,7 @@ internal void RemoveAttachedAnnotation(IAttachedAnnotation attachedAnnotation, b component.RemoveAttachedAnnotation(attachedAnnotation); // let the annotation component know if (component.AttachedAnnotations.Count == 0) { // if it has no more attached annotations, remove it - if (component.PresentationContext != null) - component.PresentationContext.RemoveFromHost(component, reorder); + component.PresentationContext?.RemoveFromHost(component, reorder); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AnnotationHighlightLayer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AnnotationHighlightLayer.cs index 65da4d051c2..a97e070a214 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AnnotationHighlightLayer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AnnotationHighlightLayer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -876,13 +876,11 @@ internal void UpdateOwners() if (_cachedTopOwner != TopOwner) { //remove it from the old owner children - if (_cachedTopOwner != null) - _cachedTopOwner.RemoveChild(this); + _cachedTopOwner?.RemoveChild(this); _cachedTopOwner = TopOwner; //add it to the new owner children - if (_cachedTopOwner != null) - _cachedTopOwner.AddChild(this); + _cachedTopOwner?.AddChild(this); } Fill = OwnerColor; } @@ -894,8 +892,7 @@ internal void UpdateOwners() /// internal void Discard() { - if (TopOwner != null) - TopOwner.RemoveChild(this); + TopOwner?.RemoveChild(this); _activeOwners.Clear(); _owners.Clear(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/MarkedHighlightComponent.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/MarkedHighlightComponent.cs index 3da58ffa113..92c5ff995c1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/MarkedHighlightComponent.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/MarkedHighlightComponent.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -550,16 +550,14 @@ private void SetState() { if (_state == 0) { - if (_highlightAnchor != null) - _highlightAnchor.Activate(false); + _highlightAnchor?.Activate(false); MarkerBrush = new SolidColorBrush(DefaultMarkerColor); StrokeThickness = MarkerStrokeThickness; _DPHost.SetValue(StickyNoteControl.IsActiveProperty, false); } else { - if (_highlightAnchor != null) - _highlightAnchor.Activate(true); + _highlightAnchor?.Activate(true); MarkerBrush = new SolidColorBrush(DefaultActiveMarkerColor); StrokeThickness = ActiveMarkerStrokeThickness; _DPHost.SetValue(StickyNoteControl.IsActiveProperty, true); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/JournalNavigationScope.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/JournalNavigationScope.cs index 9f3afdaaade..0f53cd69bb8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/JournalNavigationScope.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/JournalNavigationScope.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -226,7 +226,7 @@ public void AddBackEntry(CustomContentState state) public JournalEntry RemoveBackEntry() { _host.VerifyContextAndObjectState(); - return _journal == null ? null : _journal.RemoveBackEntry(); + return _journal?.RemoveBackEntry(); } public System.Collections.IEnumerable BackStack @@ -330,10 +330,7 @@ internal bool NavigateToEntry(JournalEntry entry) internal void AbortJournalNavigation() { - if (_journal != null) - { - _journal.AbortJournalNavigation(); - } + _journal?.AbortJournalNavigation(); } internal INavigatorBase FindTarget(string name) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/Journaling.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/Journaling.cs index 757b426d118..2bcae3d9def 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/Journaling.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/Journaling.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -564,7 +564,7 @@ internal override bool Navigate(INavigator navigator, NavigationMode navMode) // Special case: doing fragment navigation or CustomContentState navigation // within a PF. Then don't create a new PF object! IDownloader idl = navigator as IDownloader; - NavigationService ns = idl != null ? idl.Downloader : null; + NavigationService ns = idl?.Downloader; Debug.Assert(ns != null, "Fragment navigation won't work when the INavigator doesn't have a NavigationService."); PageFunctionBase pageFunction = @@ -700,10 +700,7 @@ private void InitializeComponent(PageFunctionBase pageFunction) { // Need to explicitly add a call to InitializeComponent() for Page IComponentConnector iComponentConnector = pageFunction as IComponentConnector; - if (iComponentConnector != null) - { - iComponentConnector.InitializeComponent(); - } + iComponentConnector?.InitializeComponent(); } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasFeedbackAdorner.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasFeedbackAdorner.cs index a0f118b5c72..4632df9282b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasFeedbackAdorner.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasFeedbackAdorner.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -27,7 +27,7 @@ private InkCanvasFeedbackAdorner() : base(null) { } /// /// The adorned InkCanvas internal InkCanvasFeedbackAdorner(InkCanvas inkCanvas) - : base((inkCanvas != null ? inkCanvas.InnerCanvas : null)) + : base((inkCanvas?.InnerCanvas)) { ArgumentNullException.ThrowIfNull(inkCanvas); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasSelectionAdorner.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasSelectionAdorner.cs index ef2e8d37411..d93b62a9927 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasSelectionAdorner.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasSelectionAdorner.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -69,10 +69,7 @@ internal InkCanvasSelectionAdorner(UIElement adornedElement) } finally { - if (dc != null) - { - dc.Close(); - } + dc?.Close(); } hatchDG.Freeze(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/TemplatedAdorner.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/TemplatedAdorner.cs index dea11cab1bc..2a432c899a5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/TemplatedAdorner.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/TemplatedAdorner.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -159,10 +159,7 @@ protected override Size ArrangeOverride(Size size) finalSize = base.ArrangeOverride(size); - if (_child != null) - { - _child.Arrange(new Rect(new Point(), finalSize)); - } + _child?.Arrange(new Rect(new Point(), finalSize)); return finalSize; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/BindingExpressionUncommonField.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/BindingExpressionUncommonField.cs index 01c6b26a5f4..8d240199dce 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/BindingExpressionUncommonField.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/BindingExpressionUncommonField.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -26,10 +26,7 @@ internal class BindingExpressionUncommonField : UncommonField internal new void ClearValue(DependencyObject instance) { BindingExpression bindingExpr = GetValue(instance); - if (bindingExpr != null) - { - bindingExpr.Detach(); - } + bindingExpr?.Detach(); base.ClearValue(instance); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ClrBindingWorker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ClrBindingWorker.cs index 2b5997fb4a4..47e7ed4b14b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ClrBindingWorker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ClrBindingWorker.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -196,10 +196,7 @@ internal override void AttachDataItem() internal override void DetachDataItem() { PW.DetachFromRootItem(); - if (XmlWorker != null) - { - XmlWorker.DetachDataItem(); - } + XmlWorker?.DetachDataItem(); // cancel any pending async requests. If it has already completed, // but is now waiting in the dispatcher queue, it will be ignored because @@ -251,8 +248,7 @@ internal override void UpdateValue(object value) internal override void OnCurrentChanged(ICollectionView collectionView, EventArgs args) { - if (XmlWorker != null) - XmlWorker.OnCurrentChanged(collectionView, args); + XmlWorker?.OnCurrentChanged(collectionView, args); PW.OnCurrentChanged(collectionView); } @@ -342,10 +338,7 @@ internal void NewValueAvailable(bool dependencySourcesChanged, bool initialValue // this method is called when the last item in the path is replaced. // BindingGroup also wants to know about this. BindingGroup bindingGroup = parent.BindingGroup; - if (bindingGroup != null) - { - bindingGroup.UpdateTable(parent); - } + bindingGroup?.UpdateTable(parent); if (dependencySourcesChanged) { @@ -405,10 +398,7 @@ internal void OnSourcePropertyChanged(object o, string propName) if (ParentBindingExpression.TargetWantsCrossThreadNotifications) { LiveShapingItem lsi = TargetElement as LiveShapingItem; - if (lsi != null) - { - lsi.OnCrossThreadPropertyChange(TargetProperty); - } + lsi?.OnCrossThreadPropertyChange(TargetProperty); } Engine.Marshal( @@ -538,10 +528,7 @@ internal void ReportRawValueErrors(int k, object item, object info) internal void ReportBadXPath(TraceEventType traceType) { XmlBindingWorker xmlWorker = XmlWorker; - if (xmlWorker != null) - { - xmlWorker.ReportBadXPath(traceType); - } + xmlWorker?.ReportBadXPath(traceType); } //------------------------------------------------------ @@ -627,10 +614,7 @@ void RequestAsyncGetValue(object item, int level) // abandon any previous request AsyncGetValueRequest pendingGetValueRequest = (AsyncGetValueRequest)GetValue(Feature.PendingGetValueRequest, null); - if (pendingGetValueRequest != null) - { - pendingGetValueRequest.Cancel(); - } + pendingGetValueRequest?.Cancel(); // issue the new request pendingGetValueRequest = @@ -657,10 +641,7 @@ static object OnCompleteGetValueCallback(AsyncDataRequest adr) ClrBindingWorker worker = (ClrBindingWorker)request.Args[0]; DataBindEngine engine = worker.Engine; - if (engine != null) // could be null if binding has been detached - { - engine.Marshal(CompleteGetValueLocalCallback, request); - } + engine?.Marshal(CompleteGetValueLocalCallback, request); return null; } @@ -711,10 +692,7 @@ void RequestAsyncSetValue(object item, object value) // abandon any previous request AsyncSetValueRequest pendingSetValueRequest = (AsyncSetValueRequest)GetValue(Feature.PendingSetValueRequest, null); - if (pendingSetValueRequest != null) - { - pendingSetValueRequest.Cancel(); - } + pendingSetValueRequest?.Cancel(); // issue the new request pendingSetValueRequest = @@ -739,10 +717,7 @@ static object OnCompleteSetValueCallback(AsyncDataRequest adr) ClrBindingWorker worker = (ClrBindingWorker)request.Args[0]; DataBindEngine engine = worker.Engine; - if (engine != null) // could be null if binding has been detached - { - engine.Marshal(CompleteSetValueLocalCallback, request); - } + engine?.Marshal(CompleteSetValueLocalCallback, request); return null; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupInternal.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupInternal.cs index 5cf4dd3e171..215447379c1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupInternal.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupInternal.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -235,18 +235,12 @@ internal void Clear() for (int i = 0, n = ProtectedItems.Count; i < n; ++i) { CollectionViewGroupInternal subGroup = ProtectedItems[i] as CollectionViewGroupInternal; - if (subGroup != null) - { - subGroup.Clear(); - } + subGroup?.Clear(); } } ProtectedItems.Clear(); - if (_nameToGroupMap != null) - { - _nameToGroupMap.Clear(); - } + _nameToGroupMap?.Clear(); } // return the index of the given item within the list of leaves governed @@ -396,13 +390,10 @@ protected virtual int FindIndex(object item, object seed, IComparer comparer, in if (comparer != null) { IListComparer ilc = comparer as IListComparer; - if (ilc != null) - { - // reset the IListComparer before each search. This cannot be done - // any less frequently (e.g. in Root.AddToSubgroups), due to the - // possibility that the item may appear in more than one subgroup. - ilc.Reset(); - } + // reset the IListComparer before each search. This cannot be done + // any less frequently (e.g. in Root.AddToSubgroups), due to the + // possibility that the item may appear in more than one subgroup. + ilc?.Reset(); for (index = low; index < high; ++index) { @@ -511,8 +502,7 @@ internal bool Move(object item, IList list, ref int oldIndex, ref int newIndex) // the group's description has changed - notify parent protected virtual void OnGroupByChanged() { - if (Parent != null) - Parent.OnGroupByChanged(); + Parent?.OnGroupByChanged(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupRoot.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupRoot.cs index c2a3ff8473c..272a98bf163 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupRoot.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewGroupRoot.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -417,7 +417,7 @@ void InitializeGroup(CollectionViewGroupInternal group, GroupDescription parentD // create subgroups for each of the explicit names ObservableCollection explicitNames = - (groupDescription != null) ? groupDescription.GroupNames : null; + groupDescription?.GroupNames; if (explicitNames != null) { for (int k = 0, n = explicitNames.Count; k < n; ++k) @@ -481,10 +481,7 @@ void AddToSubgroups(object item, LiveShapingItem lsi, CollectionViewGroupInterna if (name == UseAsItemDirectly) { // the item belongs to the group itself (not to any subgroups) - if (lsi != null) - { - lsi.AddParentGroup(group); - } + lsi?.AddParentGroup(group); if (loading) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs index b246dca732f..a37e9283327 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -169,10 +169,7 @@ public override ReadOnlyObservableCollection Groups public override void Refresh() { IndexedEnumerable indexer = (IndexedEnumerable)Interlocked.Exchange(ref _indexer, null); - if (indexer != null) - { - indexer.Invalidate(); - } + indexer?.Invalidate(); ProxiedView.Refresh(); } @@ -803,7 +800,7 @@ bool ICollectionViewLiveShaping.CanChangeLiveGrouping get { ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping; - return (cvls != null) ? cvls.IsLiveSorting : null; + return cvls?.IsLiveSorting; } set { @@ -826,7 +823,7 @@ bool ICollectionViewLiveShaping.CanChangeLiveGrouping get { ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping; - return (cvls != null) ? cvls.IsLiveFiltering : null; + return cvls?.IsLiveFiltering; } set { @@ -849,7 +846,7 @@ bool ICollectionViewLiveShaping.CanChangeLiveGrouping get { ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping; - return (cvls != null) ? cvls.IsLiveGrouping : null; + return cvls?.IsLiveGrouping; } set { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CompositeCollectionView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CompositeCollectionView.cs index 0c053c99a19..2e0cd00dcf7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CompositeCollectionView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CompositeCollectionView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -410,8 +410,7 @@ protected override void ProcessCollectionChanged(NotifyCollectionChangedEventArg Debug.Assert(startingIndex >= 0, "Source composite collection failed to supply an index"); int index = startingIndex; - if (_traceLog != null) - _traceLog.Add("ProcessCollectionChanged action = {0} item = {1}", + _traceLog?.Add("ProcessCollectionChanged action = {0} item = {1}", args.Action, TraceLog.IdFor(item)); CollectionContainer cc = item as CollectionContainer; @@ -612,8 +611,7 @@ protected override void ProcessCollectionChanged(NotifyCollectionChangedEventArg case NotifyCollectionChangedAction.Reset: { - if (_traceLog != null) - _traceLog.Add("ProcessCollectionChanged action = {0}", args.Action); + _traceLog?.Add("ProcessCollectionChanged action = {0}", args.Action); if (_collection.Count != 0) { @@ -779,8 +777,7 @@ internal void OnContainedCollectionChanged(object sender, NotifyCollectionChange case NotifyCollectionChangedAction.Reset: { - if (_traceLog != null) - _traceLog.Add("ContainerCollectionChange from {0} action = {1}", + _traceLog?.Add("ContainerCollectionChange from {0} action = {1}", TraceLog.IdFor(sender), args.Action); UpdateCurrencyAfterRefresh(sender); @@ -827,10 +824,7 @@ internal override bool HasReliableHashCodes() internal override void GetCollectionChangedSources(int level, Action> format, List sources) { format(level, this, false, sources); - if (_collection != null) - { - _collection.GetCollectionChangedSources(level + 1, format, sources); - } + _collection?.GetCollectionChangedSources(level + 1, format, sources); } #endregion @@ -1430,8 +1424,7 @@ void InitializeTraceLog() private void TraceContainerCollectionChange(object sender, NotifyCollectionChangedAction action, object oldItem, object newItem) { - if (_traceLog != null) - _traceLog.Add("ContainerCollectionChange from {0} action = {1} oldItem = {2} newItem = {3}", + _traceLog?.Add("ContainerCollectionChange from {0} action = {1} oldItem = {2} newItem = {3}", TraceLog.IdFor(sender), action, TraceLog.IdFor(oldItem), TraceLog.IdFor(newItem)); } @@ -1532,7 +1525,7 @@ public bool MoveNext() if (cc != null) { IEnumerable ie = cc.View; // View is null when Collection is null - _containerEnumerator = (ie != null) ? ie.GetEnumerator() : null; + _containerEnumerator = ie?.GetEnumerator(); continue; } @@ -1590,10 +1583,7 @@ public void Dispose() private void DisposeContainerEnumerator() { IDisposable d = _containerEnumerator as IDisposable; - if (d != null) - { - d.Dispose(); - } + d?.Dispose(); _containerEnumerator = null; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/DataBindEngine.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/DataBindEngine.cs index 5c6b7092c4c..1295d6572c9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/DataBindEngine.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/DataBindEngine.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -622,10 +622,7 @@ private void OnShutDown() foreach (object o in asyncDispatchers.Keys) { IAsyncDataDispatcher dispatcher = o as IAsyncDataDispatcher; - if (dispatcher != null) - { - dispatcher.CancelAllRequests(); - } + dispatcher?.CancelAllRequests(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/EnumerableCollectionView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/EnumerableCollectionView.cs index 8c6126bda58..3ec0139d163 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/EnumerableCollectionView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/EnumerableCollectionView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -550,10 +550,7 @@ void LoadSnapshotCore(IEnumerable source) // we're done with an enumerator - dispose it IDisposable id = ie as IDisposable; - if (id != null) - { - id.Dispose(); - } + id?.Dispose(); } // if the IEnumerable has changed, bring the snapshot up to date. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/IndexedEnumerable.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/IndexedEnumerable.cs index 5766fb23659..dab9716ec36 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/IndexedEnumerable.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/IndexedEnumerable.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -91,7 +91,7 @@ internal int IndexOf(object item) return _cachedIndex; } - // If item != cached item, that doesn’t mean that the enumerator + // If item != cached item, that doesn’t mean that the enumerator // is `blown, it just means we have to go find the item represented by item. index = -1; // only ask for fresh enumerator if current enumerator already was moved before @@ -183,10 +183,7 @@ internal bool IsEmpty _cachedIsEmpty = !ie.MoveNext(); IDisposable d = ie as IDisposable; - if (d != null) - { - d.Dispose(); - } + d?.Dispose(); if (_cachedIsEmpty.Value) _cachedCount = 0; @@ -457,10 +454,7 @@ private void InvalidateEnumerator() private void DisposeEnumerator(ref IEnumerator ie) { IDisposable d = ie as IDisposable; - if (d != null) - { - d.Dispose(); - } + d?.Dispose(); ie = null; } @@ -765,10 +759,7 @@ object IEnumerator.Current public void Dispose() { IDisposable d = _enumerator as IDisposable; - if (d != null) - { - d.Dispose(); - } + d?.Dispose(); _enumerator = null; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/LiveShapingList.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/LiveShapingList.cs index b7e9b19356b..cf5476e117f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/LiveShapingList.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/LiveShapingList.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -184,7 +184,7 @@ internal void SetLiveShapingProperties(LiveShapingFlags flags) // if no explicit list, use the group description properties groupingProperties = new Collection(); ICollectionView icv = View as ICollectionView; - ObservableCollection groupDescriptions = (icv != null) ? icv.GroupDescriptions : null; + ObservableCollection groupDescriptions = icv?.GroupDescriptions; if (groupDescriptions != null) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ObjectRef.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ObjectRef.cs index c842b0fc10b..8ba8174bd16 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ObjectRef.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ObjectRef.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -484,7 +484,7 @@ private object GetPreviousData(DependencyObject d) else { child = d as FrameworkElement; - parent = ((child != null) ? child.Parent : null) as System.Windows.Controls.Primitives.GridViewRowPresenterBase; + parent = (child?.Parent) as System.Windows.Controls.Primitives.GridViewRowPresenterBase; } if (child != null && parent != null && diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/PropertyPathWorker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/PropertyPathWorker.cs index 7bc06aa6e95..9e269c62679 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/PropertyPathWorker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/PropertyPathWorker.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -122,7 +122,7 @@ internal string SourcePropertyName return (dp != null) ? dp.Name : (pi != null) ? pi.Name : (pd != null) ? pd.Name : - (dpa != null) ? dpa.PropertyName : null; + dpa?.PropertyName; case SourceValueType.Indexer: // return the indexer string, e.g. "[foo]" @@ -364,9 +364,9 @@ internal void SetValue(object item, object value) { ((DependencyObject)item).SetValue(dp, value); } - else if (dpa != null) + else { - dpa.SetValue(item, value); + dpa?.SetValue(item, value); } break; @@ -698,8 +698,7 @@ private void ReplaceItem(int k, object newO, object parent) if (oldO == BindingExpression.StaticSource) { Type declaringType = (oldPI != null) ? oldPI.DeclaringType - : (oldPD != null) ? oldPD.ComponentType - : null; + : oldPD?.ComponentType; if (declaringType != null) { StaticPropertyChangedEventManager.RemoveHandler(declaringType, OnStaticPropertyChanged, SVI[k].propertyName); @@ -870,8 +869,7 @@ private void ReplaceItem(int k, object newO, object parent) if (newO == BindingExpression.StaticSource) { Type declaringType = (newPI != null) ? newPI.DeclaringType - : (newPD != null) ? newPD.ComponentType - : null; + : newPD?.ComponentType; if (declaringType != null) { StaticPropertyChangedEventManager.AddHandler(declaringType, OnStaticPropertyChanged, SVI[k].propertyName); @@ -925,7 +923,7 @@ void ReportNoInfoError(int k, object parent) // report cannot find info. Ignore when in priority bindings. if (TraceData.IsEnabled) { - BindingExpression bindingExpression = (_host != null) ? _host.ParentBindingExpression : null; + BindingExpression bindingExpression = _host?.ParentBindingExpression; if (bindingExpression == null || !bindingExpression.IsInPriorityBindingExpression) { if (!SystemXmlHelper.IsEmptyXmlDataCollection(parent)) @@ -1555,21 +1553,18 @@ private object RawValue(int k) if (CriticalExceptions.IsCriticalApplicationException(ex)) throw; BindingOperations.LogException(ex); - if (_host != null) - _host.ReportGetValueError(k, item, ex); + _host?.ReportGetValueError(k, item, ex); } catch // non CLS compliant exception { - if (_host != null) - _host.ReportGetValueError(k, item, new InvalidOperationException(SR.Format(SR.NonCLSException, "GetValue"))); + _host?.ReportGetValueError(k, item, new InvalidOperationException(SR.Format(SR.NonCLSException, "GetValue"))); } // catch the pseudo-exception as well if (o == IListIndexOutOfRange) { o = DependencyProperty.UnsetValue; - if (_host != null) - _host.ReportGetValueError(k, item, new ArgumentOutOfRangeException("index")); + _host?.ReportGetValueError(k, item, new ArgumentOutOfRangeException("index")); } #pragma warning restore 56500 @@ -1578,10 +1573,7 @@ private object RawValue(int k) return o; } - if (_host != null) - { - _host.ReportRawValueErrors(k, item, info); - } + _host?.ReportRawValueErrors(k, item, info); return DependencyProperty.UnsetValue; } @@ -1714,7 +1706,7 @@ bool DetermineWhetherDBNullIsValid(object item) SetPropertyInfo(_arySVS[Length - 1].info, out pi, out pd, out dp, out dpa); string columnName = (pd != null) ? pd.Name : - (pi != null) ? pi.Name : null; + pi?.Name; object arg = (columnName == "Item" && pi != null) ? _arySVS[Length - 1].args[0] : null; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/StaticPropertyChangedEventManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/StaticPropertyChangedEventManager.cs index 9d9a13acecb..952e791a3bd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/StaticPropertyChangedEventManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/StaticPropertyChangedEventManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -350,9 +350,9 @@ public ListenerList GetListenerList(string propertyName) // source has changed a particular property. Notify targets // who are listening either for this property or for all properties. PropertyRecord pr = (PropertyRecord)_dict[propertyName]; - ListenerList listeners = (pr == null) ? null : pr.List; + ListenerList listeners = pr?.List; PropertyRecord genericRecord = (PropertyRecord)_dict[String.Empty]; - ListenerList genericListeners = (genericRecord == null) ? null : genericRecord.List; + ListenerList genericListeners = genericRecord?.List; if (genericListeners == null) { @@ -388,7 +388,7 @@ public ListenerList GetListenerList(string propertyName) // source has changed all properties. Notify all targets. // Use previously calculated combined list, if available. PropertyRecord pr = (PropertyRecord)_dict[AllListenersKey]; - ListenerList pcList = (pr == null) ? null : pr.List; + ListenerList pcList = pr?.List; if (pcList == null) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs index 203d24acd21..c900156ee75 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -655,10 +655,7 @@ internal void RegisterCollectionSynchronizationCallback( { ViewRecord vr = (ViewRecord)de.Value; CollectionView cv = vr.View as CollectionView; - if (cv != null) - { - cv.SetAllowsCrossThreadChanges(isSynchronized); - } + cv?.SetAllowsCrossThreadChanges(isSynchronized); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/XmlBindingWorker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/XmlBindingWorker.cs index fe2cc0c5a02..09a5b0cd9c8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/XmlBindingWorker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/XmlBindingWorker.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -261,7 +261,7 @@ private XmlDataProvider XmlDataProvider if ((xdc = itemsSource as XmlDataCollection) == null) { ICollectionView icv = itemsSource as ICollectionView; - xdc = ((icv != null) ? icv.SourceCollection : null) as XmlDataCollection; + xdc = (icv?.SourceCollection) as XmlDataCollection; } if (xdc != null) @@ -521,7 +521,7 @@ private XmlNodeList SelectNodes() if (TraceData.IsEnabled) { TraceData.TraceAndNotify(TraceEventType.Error, TraceData.CannotGetXmlNodeCollection, ParentBindingExpression, - traceParameters: new object[] { (ContextNode != null) ? ContextNode.Name : null, XPath, ParentBindingExpression, xe }, + traceParameters: new object[] { ContextNode?.Name, XPath, ParentBindingExpression, xe }, eventParameters: new object[] { xe }); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/DataStreams.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/DataStreams.cs index 93de5d6ac3c..417a98c111f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/DataStreams.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/DataStreams.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -315,10 +315,7 @@ private void LoadState(object node) // B. If the loose xaml file has been changed since the journal data was created // // - if (customJournalingObject != null) - { - customJournalingObject.RestoreJournalState(state); - } + customJournalingObject?.RestoreJournalState(state); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/BamlResourceDeserializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/BamlResourceDeserializer.cs index ee5c731e34f..d0608348f0c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/BamlResourceDeserializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/BamlResourceDeserializer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -302,8 +302,7 @@ private BamlTree LoadBamlImp(Stream bamlSteam) private void PushNodeToStack(BamlTreeNode node) { - if (_currentParent != null) - _currentParent.AddChild(node); + _currentParent?.AddChild(node); _bamlTreeStack.Push(node); _currentParent = node; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs index 3a5de2b7930..8ec2ee1efee 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -490,11 +490,11 @@ internal static DependencyObject GetTemplatedParent(DependencyObject d) internal static System.Windows.Data.XmlDataProvider XmlDataProviderForElement(DependencyObject d) { MS.Internal.Controls.IGeneratorHost host = Helper.GeneratorHostForElement(d); - System.Windows.Controls.ItemCollection ic = (host != null) ? host.View : null; - ICollectionView icv = (ic != null) ? ic.CollectionView : null; + System.Windows.Controls.ItemCollection ic = host?.View; + ICollectionView icv = ic?.CollectionView; MS.Internal.Data.XmlDataCollection xdc = (icv != null) ? icv.SourceCollection as MS.Internal.Data.XmlDataCollection : null; - return (xdc != null) ? xdc.ParentXmlDataProvider : null; + return xdc?.ParentXmlDataProvider; } #if CF_Envelope_Activation_Enabled @@ -536,10 +536,7 @@ internal static Size ArrangeElementWithSingleChild(UIElement element, Size arran { UIElement child = (VisualTreeHelper.GetChildrenCount(element) > 0) ? VisualTreeHelper.GetChild(element, 0) as UIElement : null; - if (child != null) - { - child.Arrange(new Rect(arrangeSize)); - } + child?.Arrange(new Rect(arrangeSize)); return arrangeSize; } @@ -838,10 +835,7 @@ internal static List> GetItemValues(DependencyObject o Debug.Assert(item != null); List> itemValues = null; - if (itemValueStorage != null) - { - itemValueStorage.TryGetValue(item, out itemValues); - } + itemValueStorage?.TryGetValue(item, out itemValues); return itemValues; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/PackageFilter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/PackageFilter.cs index efa3129eaac..ee721e8bf41 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/PackageFilter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/PackageFilter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -556,7 +556,7 @@ private string FileTypeGuidFromMimeType(ContentType contentType) // Get the string in value Extension of key \HKEY_CLASSES_ROOT\MIME\Database\Content Type\. RegistryKey mimeContentType = FindSubkey(Registry.ClassesRoot, _mimeContentTypeKey); - RegistryKey mimeTypeKey = (mimeContentType == null ? null : mimeContentType.OpenSubKey(contentType.ToString())); + RegistryKey mimeTypeKey = (mimeContentType?.OpenSubKey(contentType.ToString())); if (mimeTypeKey == null) { return null; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XamlFilter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XamlFilter.cs index c67be78a067..c441a712766 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XamlFilter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XamlFilter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -808,10 +808,7 @@ private IndexingContentUnit ProcessFixedPage() /// private void CreateXmlReader() { - if (_xamlReader != null) - { - _xamlReader.Close(); - } + _xamlReader?.Close(); _xamlReader = new XmlTextReader(_xamlStream); // Do not return pretty-pretting spacing between tags as data. ((XmlTextReader)_xamlReader).WhitespaceHandling = WhitespaceHandling.Significant; @@ -822,10 +819,7 @@ private void CreateXmlReader() private void EnsureXmlReaderIsClosed() { - if (_xamlReader != null) - { - _xamlReader.Close(); - } + _xamlReader?.Close(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/EditingCoordinator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/EditingCoordinator.cs index c494e6be139..e3191ad79c1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/EditingCoordinator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/EditingCoordinator.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -598,10 +598,7 @@ private void PushEditingBehavior(EditingBehavior newEditingBehavior) EditingBehavior behavior = ActiveEditingBehavior; // Deactivate the previous behavior - if ( behavior != null ) - { - behavior.Deactivate(); - } + behavior?.Deactivate(); // Activate the new behavior. _activationStack.Push(newEditingBehavior); @@ -871,11 +868,8 @@ internal void OnInkCanvasDeviceUp(object sender, InputEventArgs args) { // The follow code raises variety editing events. // The out-side code could throw exception in the their handlers. We use try/finally block to protect our status. - if ( ActiveEditingBehavior != null ) - { - // Commit the current editing. - ActiveEditingBehavior.Commit(true); - } + // Commit the current editing. + ActiveEditingBehavior?.Commit(true); } finally { @@ -949,10 +943,7 @@ private void InitializeCapture(InputDevice inputDevice, IStylusEditing stylusEdi { // Reset the dynamic renderer for InkCollectionBehavior InkCollectionBehavior inkCollectionBehavior = stylusEditingBehavior as InkCollectionBehavior; - if ( inkCollectionBehavior != null ) - { - inkCollectionBehavior.ResetDynamicRenderer(); - } + inkCollectionBehavior?.ResetDynamicRenderer(); } stylusEditingBehavior.AddStylusPoints(stylusPoints, userInitiated); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/EraserBehavior.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/EraserBehavior.cs index a27fa392eb1..f0597e33ce9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/EraserBehavior.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/EraserBehavior.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -49,9 +49,9 @@ internal EraserBehavior(EditingCoordinator editingCoordinator, InkCanvas inkCanv /// /// Overrides SwitchToMode as the following expectations /// 19. From EraseByPoint To InkAndGesture - /// After mode change ink is being collected. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. + /// After mode change ink is being collected. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. /// 20. From EraseByPoint To GestureOnly - /// After mode change ink is being collected. On StylusUp gesture event fires. Stroke gets removed on StylusUp even if it’s not a gesture. + /// After mode change ink is being collected. On StylusUp gesture event fires. Stroke gets removed on StylusUp even if it’s not a gesture. /// 21. From EraseByPoint To Ink /// Ink collection starts when changing the mode. /// 22. From EraseByPoint To EraseByStroke @@ -61,9 +61,9 @@ internal EraserBehavior(EditingCoordinator editingCoordinator, InkCanvas inkCanv /// 24. From EraseByPoint To None /// No erasing is performed after mode change. /// 25. From EraseByStroke To InkAndGesture - /// After mode change ink is being collected. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. + /// After mode change ink is being collected. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. /// 26. From EraseByStroke To GestureOnly - /// After mode change ink is being collected. On StylusUp gesture event fires. Stroke gets removed on StylusUp even if it’s not a gesture. + /// After mode change ink is being collected. On StylusUp gesture event fires. Stroke gets removed on StylusUp even if it’s not a gesture. /// 27. From EraseByStroke To EraseByPoint /// After mode change PointErasing is performed. /// 28. From EraseByStroke To Ink @@ -107,8 +107,7 @@ protected override void OnSwitchToMode(InkCanvasEditingMode mode) case InkCanvasEditingMode.Select: { // Make a copy of the current cached points. - StylusPointCollection cachedPoints = _stylusPoints != null ? - _stylusPoints.Clone() : null; + StylusPointCollection cachedPoints = _stylusPoints?.Clone(); // Commit the current behavior. Commit(true); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/InkCollectionBehavior.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/InkCollectionBehavior.cs index 5ea49295a94..4452019bf33 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/InkCollectionBehavior.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/InkCollectionBehavior.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -63,9 +63,9 @@ internal void ResetDynamicRenderer() /// Overrides SwitchToMode /// As the following expected results /// 1. From Ink To InkAndGesture - /// Packets between StylusDown and StylusUp are sent to the gesture reco. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. + /// Packets between StylusDown and StylusUp are sent to the gesture reco. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. /// 2. From Ink To GestureOnly - /// Packets between StylusDown and StylusUp are send to the gesture reco. On StylusUp gesture event fires. Stroke gets removed on StylusUp even if it’s not a gesture. + /// Packets between StylusDown and StylusUp are send to the gesture reco. On StylusUp gesture event fires. Stroke gets removed on StylusUp even if it’s not a gesture. /// 3. From Ink To EraseByPoint /// Stroke is discarded. PointErasing is performed after changing the mode. /// 4. From Ink To EraseByStroke @@ -77,7 +77,7 @@ internal void ResetDynamicRenderer() /// 7. From InkAndGesture To Ink /// Stroke is collected for all packets between StylusDown and StylusUp. Gesture event does not fire. /// 8. From InkAndGesture To GestureOnly - /// Packets between StylusDown and StylusUp are sent to the gesture reco. Stroke gets removed on StylusUp even if it’s not a gesture. + /// Packets between StylusDown and StylusUp are sent to the gesture reco. Stroke gets removed on StylusUp even if it’s not a gesture. /// 9. From InkAndGesture To EraseByPoint /// Stroke is discarded. PointErasing is performed after changing the mode, gesture event does not fire. /// 10. From InkAndGesture To EraseByStroke @@ -87,7 +87,7 @@ internal void ResetDynamicRenderer() /// 12. From InkAndGesture To None /// Stroke is discarded, no gesture is recognized. /// 13. From GestureOnly To InkAndGesture - /// Packets between StylusDown and StylusUp are sent to the gesture reco. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. + /// Packets between StylusDown and StylusUp are sent to the gesture reco. On StylusUp gesture event fires. If it’s not a gesture, StrokeCollected event fires. /// 14. From GestureOnly To Ink /// Stroke is collected. Gesture event does not fire. /// 15. From GestureOnly To EraseByPoint @@ -127,8 +127,7 @@ protected override void OnSwitchToMode(InkCanvasEditingMode mode) case InkCanvasEditingMode.Select: { // Make a copy of the current cached points. - StylusPointCollection cachedPoints = _stylusPoints != null ? - _stylusPoints.Clone() : null; + StylusPointCollection cachedPoints = _stylusPoints?.Clone(); // Discard the collected ink. Commit(false); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/LassoHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/LassoHelper.cs index dd9fef6bdbe..b13a69000ff 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/LassoHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/LassoHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -148,10 +148,7 @@ private void AddLassoPoint(Point lassoPoint) } finally { - if (dc != null) - { - dc.Close(); - } + dc?.Close(); } // Add the new visual to the container. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/PenCursorManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/PenCursorManager.cs index 2b7e87da383..ba81c207fe2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/PenCursorManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/PenCursorManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -261,10 +261,7 @@ private static DrawingVisual CreateCursorDrawingVisual(Drawing drawing, int widt } finally { - if ( dc != null ) - { - dc.Close(); - } + dc?.Close(); } return drawingVisual; @@ -416,10 +413,7 @@ private static Drawing CreatePenDrawing(DrawingAttributes drawingAttributes, boo } finally { - if ( dc != null ) - { - dc.Close(); - } + dc?.Close(); } return penDrawing; @@ -535,10 +529,7 @@ private static Drawing CreateStrokeEraserDrawing() } finally { - if ( dc != null ) - { - dc.Close(); - } + dc?.Close(); } return drawingGroup; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/BreakRecordTable.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/BreakRecordTable.cs index cfbe01fcc51..a41aab2c9bd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/BreakRecordTable.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/BreakRecordTable.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -413,10 +413,7 @@ private void InvalidateBreakRecords(int start, int count) { ((FlowDocumentPage)pageRef.Target).Dispose(); } - if (_breakRecords[index].BreakRecord != null) - { - _breakRecords[index].BreakRecord.Dispose(); - } + _breakRecords[index].BreakRecord?.Dispose(); // Remov the entry. _breakRecords.RemoveAt(index); index--; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/CellParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/CellParagraph.cs index 0bfa8556c22..7781a210c7e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/CellParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/CellParagraph.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -100,7 +100,7 @@ internal void FormatCellFinite( { if (PTS.ToBoolean(fEmptyOK)) { - if (cellParaClient != null) { cellParaClient.Dispose(); } + cellParaClient?.Dispose(); if (pfsbrkcellOut != IntPtr.Zero) { PTS.Validate(PTS.FsDestroySubpageBreakRecord(cellParaClient.PtsContext.Context, pfsbrkcellOut), cellParaClient.PtsContext); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParagraph.cs index c75b411089f..fb8fcee5993 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParagraph.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -398,10 +398,7 @@ internal void UpdGetSegmentChange( dcpPara += para.Cch; para = para.Next; } - if (para != null) - { - para.SetUpdateInfo(PTS.FSKCHANGE.fskchInside, false); - } + para?.SetUpdateInfo(PTS.FSKCHANGE.fskchInside, false); } else { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParaClient.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParaClient.cs index 70d4cf98425..6918213d09b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParaClient.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParaClient.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -44,10 +44,7 @@ public override void Dispose() SubpageHandle = IntPtr.Zero; } - if(_pageContext != null) - { - _pageContext.RemoveFloatingParaClient(this); - } + _pageContext?.RemoveFloatingParaClient(this); base.Dispose(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParagraph.cs index 044ff5f2b20..2848754b567 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParagraph.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -416,10 +416,7 @@ by incorporating column gap information */ // ------------------------------------------------------------------ internal override void ClearUpdateInfo() { - if (_mainTextSegment != null) - { - _mainTextSegment.ClearUpdateInfo(); - } + _mainTextSegment?.ClearUpdateInfo(); base.ClearUpdateInfo(); } @@ -449,10 +446,7 @@ internal override bool InvalidateStructure(int startPosition) // ------------------------------------------------------------------ internal override void InvalidateFormatCache() { - if (_mainTextSegment != null) - { - _mainTextSegment.InvalidateFormatCache(); - } + _mainTextSegment?.InvalidateFormatCache(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParaClient.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParaClient.cs index 481b283c52f..2b49427092b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParaClient.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParaClient.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -48,10 +48,7 @@ internal FloaterParaClient(FloaterParagraph paragraph) // ------------------------------------------------------------------ public override void Dispose() { - if(_pageContext != null) - { - _pageContext.RemoveFloatingParaClient(this); - } + _pageContext?.RemoveFloatingParaClient(this); base.Dispose(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParagraph.cs index a245dc7294d..cf27bfbbbfe 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParagraph.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -586,10 +586,7 @@ internal override void GetMCSClientAfterFloater( // ------------------------------------------------------------------ internal override void ClearUpdateInfo() { - if (_mainTextSegment != null) - { - _mainTextSegment.ClearUpdateInfo(); - } + _mainTextSegment?.ClearUpdateInfo(); base.ClearUpdateInfo(); } @@ -619,10 +616,7 @@ internal override bool InvalidateStructure(int startPosition) // ------------------------------------------------------------------ internal override void InvalidateFormatCache() { - if (_mainTextSegment != null) - { - _mainTextSegment.InvalidateFormatCache(); - } + _mainTextSegment?.InvalidateFormatCache(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs index ffa0d791abc..20d32cb09ee 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -392,7 +392,7 @@ internal ReadOnlyCollection FloatingElementResults } /// - /// Called when a UIElement-derived class which is hosted by a IContentHost changes it’s DesiredSize + /// Called when a UIElement-derived class which is hosted by a IContentHost changes it’s DesiredSize /// /// /// Child element whose DesiredSize has changed @@ -817,10 +817,7 @@ private void Dispose(bool disposing) } // Dispose PTS page - if (_ptsPage != null) - { - _ptsPage.Dispose(); - } + _ptsPage?.Dispose(); } try { @@ -896,10 +893,7 @@ private void OnBeforeFormatPage() //------------------------------------------------------------------- private void OnAfterFormatPage() { - if (_textView != null) - { - _textView.Invalidate(); - } + _textView?.Invalidate(); _visualNeedsUpdate = true; } @@ -1029,10 +1023,7 @@ private void DestroyVisualLinks(ContainerVisual visual) /// private void ValidateTextView() { - if (_textView != null) - { - _textView.OnUpdated(); - } + _textView?.OnUpdated(); } /// @@ -1212,7 +1203,7 @@ IEnumerator IContentHost.HostedElements } /// - /// Called when a UIElement-derived class which is hosted by a IContentHost changes it’s DesiredSize + /// Called when a UIElement-derived class which is hosted by a IContentHost changes it’s DesiredSize /// /// /// Child element whose DesiredSize has changed diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs index 9999421b809..8d2ecefa042 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -67,10 +67,7 @@ public override void Dispose() Debug.Assert(_line != null, "Line has been already disposed."); try { - if (_line != null) - { - _line.Dispose(); - } + _line?.Dispose(); } finally { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/LineBreakRecord.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/LineBreakRecord.cs index bc4834bf2ec..179dda6c880 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/LineBreakRecord.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/LineBreakRecord.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -33,10 +33,7 @@ internal LineBreakRecord(PtsContext ptsContext, TextLineBreak textLineBreak) : b /// public override void Dispose() { - if(_textLineBreak != null) - { - _textLineBreak.Dispose(); - } + _textLineBreak?.Dispose(); base.Dispose(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/OptimalBreakSession.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/OptimalBreakSession.cs index a8dbc96795c..12cc9753637 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/OptimalBreakSession.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/OptimalBreakSession.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -37,15 +37,9 @@ public override void Dispose() { try { - if(_textParagraphCache != null) - { - _textParagraphCache.Dispose(); - } - - if(_optimalTextSource != null) - { - _optimalTextSource.Dispose(); - } + _textParagraphCache?.Dispose(); + + _optimalTextSource?.Dispose(); } finally { @@ -99,10 +93,7 @@ internal LineBreakpoint(OptimalBreakSession optimalBreakSession, TextBreakpoint /// public override void Dispose() { - if(_textBreakpoint != null) - { - _textBreakpoint.Dispose(); - } + _textBreakpoint?.Dispose(); base.Dispose(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PageVisual.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PageVisual.cs index 0e6a737141f..d23d30f8b5a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PageVisual.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PageVisual.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -90,8 +90,7 @@ internal Visual Child internal void ClearDrawingContext() { DrawingContext ctx = this.RenderOpen(); - if(ctx != null) - ctx.Close(); + ctx?.Close(); } //------------------------------------------------------------------- @@ -150,10 +149,7 @@ IEnumerator IContentHost.HostedElements void IContentHost.OnChildDesiredSizeChanged(UIElement child) { IContentHost host = _owner.Target as IContentHost; - if (host != null) - { - host.OnChildDesiredSizeChanged(child); - } + host?.OnChildDesiredSizeChanged(child); } #endregion IContentHost Members diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsCache.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsCache.cs index 8808b0981db..58ae5211e36 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsCache.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsCache.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -331,10 +331,7 @@ private void DestroyPTSContexts() PTS.IgnoreError(PTS.DestroyInstalledObjectsInfo(_contextPool[index].InstalledObjects)); // Explicitly dispose the penalty module object to ensure proper destruction // order of PTSContext and the penalty module (PTS context must be destroyed first). - if (_contextPool[index].TextPenaltyModule != null) - { - _contextPool[index].TextPenaltyModule.Dispose(); - } + _contextPool[index].TextPenaltyModule?.Dispose(); _contextPool.RemoveAt(index); } @@ -406,10 +403,7 @@ private void OnPtsContextReleased(bool cleanContextPool) PTS.Validate(PTS.DestroyInstalledObjectsInfo(_contextPool[index].InstalledObjects)); // Explicitly dispose the penalty module object to ensure proper destruction // order of PTSContext and the penalty module (PTS context must be destroyed first). - if (_contextPool[index].TextPenaltyModule != null) - { - _contextPool[index].TextPenaltyModule.Dispose(); - } + _contextPool[index].TextPenaltyModule?.Dispose(); _contextPool.RemoveAt(index); continue; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsHost.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsHost.cs index e246099b6a0..3445ae5c2a8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsHost.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsHost.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -4093,10 +4093,7 @@ internal int DestroyCell( try { CellParaClient cellParaClient = PtsContext.HandleToObject(pfsCell) as CellParaClient; - if (cellParaClient != null) - { - cellParaClient.Dispose(); - } + cellParaClient?.Dispose(); } catch (Exception e) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsPage.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsPage.cs index 9463be65fbc..efd1003111b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsPage.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsPage.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -744,10 +744,7 @@ private void OnBeforeFormatPage(bool finitePage, bool incremental) _pageContextOfThisPage.PageRect = new PTS.FSRECT(new Rect(_section.StructuralCache.CurrentFormatContext.PageSize)); // Ensure we have no background work pending - if (_backgroundFormatOperation != null) - { - _backgroundFormatOperation.Abort(); - } + _backgroundFormatOperation?.Abort(); if (!_finitePage) { @@ -805,10 +802,7 @@ private void OnAfterFormatPage(bool setSize, bool incremental) // Make sure that structural cache is in clean state after formatting // is done. - if (_section.StructuralCache != null) - { - _section.StructuralCache.ClearUpdateInfo(false); - } + _section.StructuralCache?.ClearUpdateInfo(false); } // ------------------------------------------------------------------ diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Section.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Section.cs index fcf10e48ce8..a19b9c3516a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Section.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Section.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -418,10 +418,7 @@ internal void GetEndnoteSeparators( /// internal void InvalidateFormatCache() { - if (_mainTextSegment != null) - { - _mainTextSegment.InvalidateFormatCache(); - } + _mainTextSegment?.InvalidateFormatCache(); } /// @@ -429,10 +426,7 @@ internal void InvalidateFormatCache() /// internal void ClearUpdateInfo() { - if (_mainTextSegment != null) - { - _mainTextSegment.ClearUpdateInfo(); - } + _mainTextSegment?.ClearUpdateInfo(); } /// @@ -467,10 +461,7 @@ internal void DestroyStructure() /// internal void UpdateSegmentLastFormatPositions() { - if(_mainTextSegment != null) - { - _mainTextSegment.UpdateLastFormatPositions(); - } + _mainTextSegment?.UpdateLastFormatPositions(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/StructuralCache.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/StructuralCache.cs index f390fa76d4d..40ac77e49e8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/StructuralCache.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/StructuralCache.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -164,7 +164,7 @@ internal void AddDirtyTextRange(DirtyTextRange dtr) /// List of DRTs for specified range. internal DtrList DtrsFromRange(int dcpNew, int cchOld) { - return (_dtrs != null) ? _dtrs.DtrsFromRange(dcpNew, cchOld) : null; + return _dtrs?.DtrsFromRange(dcpNew, cchOld); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/SubpageParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/SubpageParagraph.cs index 7a10a2c0fae..fdfe193075d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/SubpageParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/SubpageParagraph.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -640,10 +640,7 @@ internal unsafe void UpdateBottomlessPara( // ------------------------------------------------------------------ internal override void ClearUpdateInfo() { - if (_mainTextSegment != null) - { - _mainTextSegment.ClearUpdateInfo(); - } + _mainTextSegment?.ClearUpdateInfo(); base.ClearUpdateInfo(); } @@ -673,10 +670,7 @@ internal override bool InvalidateStructure(int startPosition) // ------------------------------------------------------------------ internal override void InvalidateFormatCache() { - if (_mainTextSegment != null) - { - _mainTextSegment.InvalidateFormatCache(); - } + _mainTextSegment?.InvalidateFormatCache(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TableParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TableParagraph.cs index 3afeb3a2c06..fcfd440f4e7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TableParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TableParagraph.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -550,16 +550,13 @@ private void TableStructureChanged(object sender, EventArgs e) // - to create dirty text range corresponding to the Table content // - notify formatter that Table's content is changed. // - int charCount = Table.SymbolCount - 2;// This is equivalent to (ContentEndOffset – ContentStartOffset) but is more performant. + int charCount = Table.SymbolCount - 2;// This is equivalent to (ContentEndOffset – ContentStartOffset) but is more performant. if (charCount > 0) { DirtyTextRange dtr = new DirtyTextRange(Table.ContentStartOffset, charCount, charCount); StructuralCache.AddDirtyTextRange(dtr); } - if (StructuralCache.FormattingOwner.Formatter != null) - { - StructuralCache.FormattingOwner.Formatter.OnContentInvalidated(true, Table.ContentStart, Table.ContentEnd); - } + StructuralCache.FormattingOwner.Formatter?.OnContentInvalidated(true, Table.ContentStart, Table.ContentEnd); } #endregion Private Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TextParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TextParagraph.cs index 81e833ae5a8..21d7af40962 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TextParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TextParagraph.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -194,7 +194,7 @@ internal void CreateOptimalBreakSession( { _textRunCache = new TextRunCache(); TextFormatter textFormatter = StructuralCache.TextFormatterHost.TextFormatter; - TextLineBreak textLineBreak = lineBreakRecord != null ? lineBreakRecord.TextLineBreak : null; + TextLineBreak textLineBreak = lineBreakRecord?.TextLineBreak; OptimalTextSource optimalTextSource = new OptimalTextSource(StructuralCache.TextFormatterHost, ParagraphStartCharacterPosition, durTrack, textParaClient, _textRunCache); StructuralCache.TextFormatterHost.Context = optimalTextSource; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/UIElementParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/UIElementParagraph.cs index 7a3c82043d5..100983f6a02 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/UIElementParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/UIElementParagraph.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -131,10 +131,7 @@ internal override void CollapseMargin( dvr += mcsNew.Margin; } } - if (mcsNew != null) - { - mcsNew.Dispose(); - } + mcsNew?.Dispose(); } //------------------------------------------------------------------- diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemCoreHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemCoreHelper.cs index 8d09399ea81..0c2f7ddb388 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemCoreHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemCoreHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -21,14 +21,14 @@ internal static bool IsIDynamicMetaObjectProvider(object item) internal static object NewDynamicPropertyAccessor(Type ownerType, string propertyName) { SystemCoreExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemCore(); - return (extensions != null) ? extensions.NewDynamicPropertyAccessor(ownerType, propertyName) : null; + return extensions?.NewDynamicPropertyAccessor(ownerType, propertyName); } // return a DynamicIndexerAccessor with the given number of arguments internal static object GetIndexerAccessor(int rank) { SystemCoreExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemCore(); - return (extensions != null) ? extensions.GetIndexerAccessor(rank) : null; + return extensions?.GetIndexerAccessor(rank); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemDataHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemDataHelper.cs index 38b7ecf0dc5..63fd63c29d2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemDataHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemDataHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -53,7 +53,7 @@ internal static bool IsDataSetCollectionProperty(PropertyDescriptor pd) internal static object GetValue(object item, PropertyDescriptor pd, bool useFollowParent) { SystemDataExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemData(); - return (extensions != null) ? extensions.GetValue(item, pd, useFollowParent) : null; + return extensions?.GetValue(item, pd, useFollowParent); } // return true if DBNull is a valid value for the given item and column. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemXmlHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemXmlHelper.cs index 271e1eafc45..18f7ba0a6df 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemXmlHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemXmlHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -67,7 +67,7 @@ internal static bool IsEmptyXmlDataCollection(object parent) internal static string GetXmlTagName(object item, DependencyObject target) { SystemXmlExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemXml(); - return (extensions != null) ? extensions.GetXmlTagName(item, target) : null; + return extensions?.GetXmlTagName(item, target); } // find a node with the given string as its InnerText @@ -82,7 +82,7 @@ internal static object FindXmlNodeWithInnerText(IEnumerable items, object innerT internal static object GetInnerText(object item) { SystemXmlExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemXml(); - return (extensions != null) ? extensions.GetInnerText(item) : null; + return extensions?.GetInnerText(item); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemXmlLinqHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemXmlLinqHelper.cs index 38b2eaaead5..5714fa83d67 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemXmlLinqHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/SystemXmlLinqHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -23,7 +23,7 @@ internal static bool IsXElement(object item) internal static string GetXElementTagName(object item) { SystemXmlLinqExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemXmlLinq(); - return (extensions != null) ? extensions.GetXElementTagName(item) : null; + return extensions?.GetXElementTagName(item); } // XLinq exposes two synthetic properties - Elements and Descendants - diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/LineProperties.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/LineProperties.cs index 4dc4c15d7a9..d5294f870f0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/LineProperties.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/LineProperties.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -120,7 +120,7 @@ internal LineProperties( TextAlignment textAlignment) { _defaultTextProperties = defaultTextProperties; - _markerProperties = (markerProperties != null) ? markerProperties.GetTextMarkerProperties(this) : null; + _markerProperties = markerProperties?.GetTextMarkerProperties(this); _flowDirection = (FlowDirection)element.GetValue(Block.FlowDirectionProperty); _textAlignment = textAlignment; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Utility/BindUriHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Utility/BindUriHelper.cs index 4d5e64dba4a..bb30c3215d8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Utility/BindUriHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Utility/BindUriHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -118,7 +118,7 @@ static internal Uri GetUriToNavigate(DependencyObject element, Uri baseUri, Uri { NavigationService ns = null; ns = element.GetValue(NavigationService.NavigationServiceProperty) as NavigationService; - currentSource = (ns == null) ? null : ns.CurrentSource; + currentSource = ns?.CurrentSource; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WeakHashtable.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WeakHashtable.cs index 5a61d3df19c..859fcd89492 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WeakHashtable.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WeakHashtable.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -59,7 +59,7 @@ public void SetWeak(object key, object value) public object UnwrapKey(object key) { EqualityWeakReference keyRef = key as EqualityWeakReference; - return (keyRef != null) ? keyRef.Target : null; + return keyRef?.Target; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs index faedef8b8bb..a10e8f3997a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -2175,10 +2175,7 @@ private void SetVerticalOffsetInternal(double offset) private void UpdateTextView() { MultiPageTextView tv = TextView as MultiPageTextView; - if (tv != null) - { - tv.OnPageLayoutChanged(); - } + tv?.OnPageLayoutChanged(); } /// @@ -2276,10 +2273,7 @@ private void InvalidateChildMeasure() { UIElement page = _childrenCollection[i] as UIElement; - if (page != null) - { - page.InvalidateMeasure(); - } + page?.InvalidateMeasure(); } } @@ -2497,15 +2491,9 @@ private void Initialize() /// private void InvalidateDocumentScrollInfo() { - if (ScrollOwner != null) - { - ScrollOwner.InvalidateScrollInfo(); - } + ScrollOwner?.InvalidateScrollInfo(); - if (DocumentViewerOwner != null) - { - DocumentViewerOwner.InvalidateDocumentScrollInfo(); - } + DocumentViewerOwner?.InvalidateDocumentScrollInfo(); } /// @@ -2642,7 +2630,7 @@ private DocumentPageView GetDocumentPageViewFromPoint(Point point) { //Hit test to find the DocumentPageView HitTestResult result = VisualTreeHelper.HitTest(this, point); - DependencyObject currentVisual = (result != null) ? result.VisualHit : null; + DependencyObject currentVisual = result?.VisualHit; DocumentPageView page = null; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGridPage.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGridPage.cs index 3c546d95a88..dfae906c686 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGridPage.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGridPage.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -337,10 +337,7 @@ protected void Dispose() //Dispose our DocumentPageView. IDisposable dpv = _documentPageView as IDisposable; - if (dpv != null) - { - dpv.Dispose(); - } + dpv?.Dispose(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentView.cs index e081755f72d..ff4157489fb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -157,10 +157,7 @@ protected sealed override Size ArrangeOverride(Size arrangeSize) // Connect to visual tree. if (_pageVisual != _formatter.DocumentPage.Visual) { - if (_textView != null) - { - _textView.OnPageConnected(); - } + _textView?.OnPageConnected(); if (_pageVisual != null) { RemoveVisualChild(_pageVisual); @@ -184,10 +181,7 @@ protected sealed override Size ArrangeOverride(Size arrangeSize) { if (_pageVisual != null) { - if (_textView != null) - { - _textView.OnPageDisconnected(); - } + _textView?.OnPageDisconnected(); RemoveVisualChild(_pageVisual); _pageVisual = null; } @@ -386,10 +380,7 @@ private void HandleFormatterSuspended(object sender, EventArgs e) // Disconnect any content associated with the formatter. if (_pageVisual != null && !_suspendLayout) { - if (_textView != null) - { - _textView.OnPageDisconnected(); - } + _textView?.OnPageDisconnected(); RemoveVisualChild(_pageVisual); _pageVisual = null; } @@ -427,10 +418,7 @@ private void HandleFormatterSuspended(object sender, EventArgs e) /// void IScrollInfo.LineUp() { - if (_scrollData != null) - { - _scrollData.LineUp(this); - } + _scrollData?.LineUp(this); } /// @@ -438,10 +426,7 @@ void IScrollInfo.LineUp() /// void IScrollInfo.LineDown() { - if (_scrollData != null) - { - _scrollData.LineDown(this); - } + _scrollData?.LineDown(this); } /// @@ -449,10 +434,7 @@ void IScrollInfo.LineDown() /// void IScrollInfo.LineLeft() { - if (_scrollData != null) - { - _scrollData.LineLeft(this); - } + _scrollData?.LineLeft(this); } /// @@ -460,10 +442,7 @@ void IScrollInfo.LineLeft() /// void IScrollInfo.LineRight() { - if (_scrollData != null) - { - _scrollData.LineRight(this); - } + _scrollData?.LineRight(this); } /// @@ -471,10 +450,7 @@ void IScrollInfo.LineRight() /// void IScrollInfo.PageUp() { - if (_scrollData != null) - { - _scrollData.PageUp(this); - } + _scrollData?.PageUp(this); } /// @@ -482,10 +458,7 @@ void IScrollInfo.PageUp() /// void IScrollInfo.PageDown() { - if (_scrollData != null) - { - _scrollData.PageDown(this); - } + _scrollData?.PageDown(this); } /// @@ -493,10 +466,7 @@ void IScrollInfo.PageDown() /// void IScrollInfo.PageLeft() { - if (_scrollData != null) - { - _scrollData.PageLeft(this); - } + _scrollData?.PageLeft(this); } /// @@ -504,10 +474,7 @@ void IScrollInfo.PageLeft() /// void IScrollInfo.PageRight() { - if (_scrollData != null) - { - _scrollData.PageRight(this); - } + _scrollData?.PageRight(this); } /// @@ -515,10 +482,7 @@ void IScrollInfo.PageRight() /// void IScrollInfo.MouseWheelUp() { - if (_scrollData != null) - { - _scrollData.MouseWheelUp(this); - } + _scrollData?.MouseWheelUp(this); } /// @@ -526,10 +490,7 @@ void IScrollInfo.MouseWheelUp() /// void IScrollInfo.MouseWheelDown() { - if (_scrollData != null) - { - _scrollData.MouseWheelDown(this); - } + _scrollData?.MouseWheelDown(this); } /// @@ -537,10 +498,7 @@ void IScrollInfo.MouseWheelDown() /// void IScrollInfo.MouseWheelLeft() { - if (_scrollData != null) - { - _scrollData.MouseWheelLeft(this); - } + _scrollData?.MouseWheelLeft(this); } /// @@ -548,10 +506,7 @@ void IScrollInfo.MouseWheelLeft() /// void IScrollInfo.MouseWheelRight() { - if (_scrollData != null) - { - _scrollData.MouseWheelRight(this); - } + _scrollData?.MouseWheelRight(this); } /// @@ -559,10 +514,7 @@ void IScrollInfo.MouseWheelRight() /// void IScrollInfo.SetHorizontalOffset(double offset) { - if (_scrollData != null) - { - _scrollData.SetHorizontalOffset(this, offset); - } + _scrollData?.SetHorizontalOffset(this, offset); } /// @@ -570,10 +522,7 @@ void IScrollInfo.SetHorizontalOffset(double offset) /// void IScrollInfo.SetVerticalOffset(double offset) { - if (_scrollData != null) - { - _scrollData.SetVerticalOffset(this, offset); - } + _scrollData?.SetVerticalOffset(this, offset); } /// @@ -702,7 +651,7 @@ ScrollViewer IScrollInfo.ScrollOwner { get { - return (_scrollData != null) ? _scrollData.ScrollOwner : null; + return _scrollData?.ScrollOwner; } set diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/IFlowDocumentViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/IFlowDocumentViewer.cs index f10334f48e5..45bd6fff188 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/IFlowDocumentViewer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/IFlowDocumentViewer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -257,10 +257,7 @@ private object SetTextSelection(object arg) /// void IFlowDocumentViewer.PreviousPage() { - if (ScrollViewer != null) - { - ScrollViewer.PageUp(); - } + ScrollViewer?.PageUp(); } /// @@ -268,10 +265,7 @@ void IFlowDocumentViewer.PreviousPage() /// void IFlowDocumentViewer.NextPage() { - if (ScrollViewer != null) - { - ScrollViewer.PageDown(); - } + ScrollViewer?.PageDown(); } /// @@ -279,10 +273,7 @@ void IFlowDocumentViewer.NextPage() /// void IFlowDocumentViewer.FirstPage() { - if (ScrollViewer != null) - { - ScrollViewer.ScrollToHome(); - } + ScrollViewer?.ScrollToHome(); } /// @@ -290,10 +281,7 @@ void IFlowDocumentViewer.FirstPage() /// void IFlowDocumentViewer.LastPage() { - if (ScrollViewer != null) - { - ScrollViewer.ScrollToEnd(); - } + ScrollViewer?.ScrollToEnd(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/ScrollData.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/ScrollData.cs index 15a66392942..065141b821d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/ScrollData.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/ScrollData.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -135,10 +135,7 @@ internal void SetHorizontalOffset(UIElement owner, double offset) { _offset.X = offset; owner.InvalidateArrange(); - if (_scrollOwner != null) - { - _scrollOwner.InvalidateScrollInfo(); - } + _scrollOwner?.InvalidateScrollInfo(); } } @@ -157,10 +154,7 @@ internal void SetVerticalOffset(UIElement owner, double offset) { _offset.Y = offset; owner.InvalidateArrange(); - if (_scrollOwner != null) - { - _scrollOwner.InvalidateScrollInfo(); - } + _scrollOwner?.InvalidateScrollInfo(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxView.cs index 682dc5e7f46..07c5a20f2b1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -73,10 +73,7 @@ object IServiceProvider.GetService(Type serviceType) /// void IScrollInfo.LineUp() { - if (_scrollData != null) - { - _scrollData.LineUp(this); - } + _scrollData?.LineUp(this); } /// @@ -84,10 +81,7 @@ void IScrollInfo.LineUp() /// void IScrollInfo.LineDown() { - if (_scrollData != null) - { - _scrollData.LineDown(this); - } + _scrollData?.LineDown(this); } /// @@ -95,10 +89,7 @@ void IScrollInfo.LineDown() /// void IScrollInfo.LineLeft() { - if (_scrollData != null) - { - _scrollData.LineLeft(this); - } + _scrollData?.LineLeft(this); } /// @@ -106,10 +97,7 @@ void IScrollInfo.LineLeft() /// void IScrollInfo.LineRight() { - if (_scrollData != null) - { - _scrollData.LineRight(this); - } + _scrollData?.LineRight(this); } /// @@ -117,10 +105,7 @@ void IScrollInfo.LineRight() /// void IScrollInfo.PageUp() { - if (_scrollData != null) - { - _scrollData.PageUp(this); - } + _scrollData?.PageUp(this); } /// @@ -128,10 +113,7 @@ void IScrollInfo.PageUp() /// void IScrollInfo.PageDown() { - if (_scrollData != null) - { - _scrollData.PageDown(this); - } + _scrollData?.PageDown(this); } /// @@ -139,10 +121,7 @@ void IScrollInfo.PageDown() /// void IScrollInfo.PageLeft() { - if (_scrollData != null) - { - _scrollData.PageLeft(this); - } + _scrollData?.PageLeft(this); } /// @@ -150,10 +129,7 @@ void IScrollInfo.PageLeft() /// void IScrollInfo.PageRight() { - if (_scrollData != null) - { - _scrollData.PageRight(this); - } + _scrollData?.PageRight(this); } /// @@ -161,10 +137,7 @@ void IScrollInfo.PageRight() /// void IScrollInfo.MouseWheelUp() { - if (_scrollData != null) - { - _scrollData.MouseWheelUp(this); - } + _scrollData?.MouseWheelUp(this); } /// @@ -172,10 +145,7 @@ void IScrollInfo.MouseWheelUp() /// void IScrollInfo.MouseWheelDown() { - if (_scrollData != null) - { - _scrollData.MouseWheelDown(this); - } + _scrollData?.MouseWheelDown(this); } /// @@ -183,10 +153,7 @@ void IScrollInfo.MouseWheelDown() /// void IScrollInfo.MouseWheelLeft() { - if (_scrollData != null) - { - _scrollData.MouseWheelLeft(this); - } + _scrollData?.MouseWheelLeft(this); } /// @@ -194,10 +161,7 @@ void IScrollInfo.MouseWheelLeft() /// void IScrollInfo.MouseWheelRight() { - if (_scrollData != null) - { - _scrollData.MouseWheelRight(this); - } + _scrollData?.MouseWheelRight(this); } /// @@ -205,10 +169,7 @@ void IScrollInfo.MouseWheelRight() /// void IScrollInfo.SetHorizontalOffset(double offset) { - if (_scrollData != null) - { - _scrollData.SetHorizontalOffset(this, offset); - } + _scrollData?.SetHorizontalOffset(this, offset); } /// @@ -216,10 +177,7 @@ void IScrollInfo.SetHorizontalOffset(double offset) /// void IScrollInfo.SetVerticalOffset(double offset) { - if (_scrollData != null) - { - _scrollData.SetVerticalOffset(this, offset); - } + _scrollData?.SetVerticalOffset(this, offset); } /// @@ -380,7 +338,7 @@ ScrollViewer IScrollInfo.ScrollOwner { get { - return (_scrollData != null) ? _scrollData.ScrollOwner : null; + return _scrollData?.ScrollOwner; } set diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs index 2757d3cb501..a3d432443a0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1039,10 +1039,7 @@ private CellInfo GetCellInfoFromPoint(ParagraphResult paragraph, Point point, Ta // WOOT! COLUMNS! cellInfo = GetCellInfoFromPoint(subpageParagraphResult.Columns, subpageParagraphResult.FloatingElements, point, tableFilter); - if (cellInfo != null) - { - cellInfo.Adjust(new Point(subpageParagraphResult.ContentOffset.X, subpageParagraphResult.ContentOffset.Y)); - } + cellInfo?.Adjust(new Point(subpageParagraphResult.ContentOffset.X, subpageParagraphResult.ContentOffset.Y)); } else if (paragraph is FigureParagraphResult) { @@ -1050,10 +1047,7 @@ private CellInfo GetCellInfoFromPoint(ParagraphResult paragraph, Point point, Ta FigureParagraphResult figureParagraphResult = (FigureParagraphResult)paragraph; TransformToSubpage(ref point, figureParagraphResult.ContentOffset); cellInfo = GetCellInfoFromPoint(figureParagraphResult.Columns, figureParagraphResult.FloatingElements, point, tableFilter); - if (cellInfo != null) - { - cellInfo.Adjust(new Point(figureParagraphResult.ContentOffset.X, figureParagraphResult.ContentOffset.Y)); - } + cellInfo?.Adjust(new Point(figureParagraphResult.ContentOffset.X, figureParagraphResult.ContentOffset.Y)); } else if (paragraph is FloaterParagraphResult) { @@ -1061,10 +1055,7 @@ private CellInfo GetCellInfoFromPoint(ParagraphResult paragraph, Point point, Ta FloaterParagraphResult floaterParagraphResult = (FloaterParagraphResult)paragraph; TransformToSubpage(ref point, floaterParagraphResult.ContentOffset); cellInfo = GetCellInfoFromPoint(floaterParagraphResult.Columns, floaterParagraphResult.FloatingElements, point, tableFilter); - if (cellInfo != null) - { - cellInfo.Adjust(new Point(floaterParagraphResult.ContentOffset.X, floaterParagraphResult.ContentOffset.Y)); - } + cellInfo?.Adjust(new Point(floaterParagraphResult.ContentOffset.X, floaterParagraphResult.ContentOffset.Y)); } if (tableFilter != null && cellInfo != null && cellInfo.Cell.Table != tableFilter) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonDialog.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonDialog.cs index 197c5ce536f..c37c4c12f7c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonDialog.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonDialog.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -119,10 +119,7 @@ public virtual Nullable ShowDialog() } finally { - if (tempParentHwnd != null) - { - tempParentHwnd.Dispose(); - } + tempParentHwnd?.Dispose(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationDocumentPaginator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationDocumentPaginator.cs index c8fa3aba558..41b8cb25bc2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationDocumentPaginator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationDocumentPaginator.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -488,10 +488,7 @@ public IInputElement InputHitTest(Point point) /// public void OnChildDesiredSizeChanged(UIElement child) { - if (_basePage != null) - { - _basePage.OnChildDesiredSizeChanged(child); - } + _basePage?.OnChildDesiredSizeChanged(child); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationHelper.cs index 43a20fa0909..00b04706265 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -662,7 +662,7 @@ internal static object GetFdrHost(FlowDocumentReader fdr) { host = StyleHelper.FindNameInTemplateContent(fdr, "PART_ContentHost", fdr.TemplateInternal) as Decorator; } - return host != null ? host.Child : null; + return host?.Child; } private static IList GetSpannedAnnotationsForFlow(AnnotationService service, ITextSelection selection) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs index e07da11d185..3d7c2522578 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -145,10 +145,7 @@ public void WriteXml(XmlWriter writer) { foreach (XmlElement content in _contents) { - if (content != null) - { - content.WriteTo(writer); - } + content?.WriteTo(writer); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs index 183bb2cbf48..f34ca563689 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -913,13 +913,10 @@ public ResourceDictionary Resources _resources = value; } - if (oldValue != null) - { - // This app is no longer an owner for the old RD - oldValue.RemoveOwner(this); - } + // This app is no longer an owner for the old RD + oldValue?.RemoveOwner(this); - if(_reloadFluentDictionary && !_resourcesInitialized) + if (_reloadFluentDictionary && !_resourcesInitialized) { if(value != null && ThemeMode != ThemeMode.None) { @@ -1656,15 +1653,9 @@ internal virtual void DoShutdown() // this will always be null in the browser hosted case since we we don't // support Activate, Deactivate, and SessionEnding events in the // browser scenario and thus we never create this hwndsource. - if (_parkingHwnd != null) - { - _parkingHwnd.Dispose(); - } + _parkingHwnd?.Dispose(); - if (_events != null) - { - _events.Dispose(); - } + _events?.Dispose(); PreloadedPackages.Clear(); AppSecurityManager.ClearSecurityManager(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs index 67f064fc1b4..0e7cebddced 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -239,8 +239,7 @@ private DateTimeAutomationPeer GetOrCreateDateTimeAutomationPeer(DateTime date, // Sets hwnd and parent info if (addParentInfo) { - if(peer != null) - peer.TrySetParentInfo(this); + peer?.TrySetParentInfo(this); } } // Set EventsSource if visual exists @@ -294,10 +293,7 @@ internal void RaiseSelectionEvents(SelectionChangedEventArgs e) if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) && numSelected == 1 && numAdded == 1) { DateTimeAutomationPeer peer = GetOrCreateDateTimeAutomationPeer((DateTime)e.AddedItems[0], CalendarMode.Month); - if (peer != null) - { - peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); - } + peer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } else { @@ -306,10 +302,7 @@ internal void RaiseSelectionEvents(SelectionChangedEventArgs e) foreach (DateTime date in e.AddedItems) { DateTimeAutomationPeer peer = GetOrCreateDateTimeAutomationPeer(date, CalendarMode.Month); - if (peer != null) - { - peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); - } + peer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); } } } @@ -319,10 +312,7 @@ internal void RaiseSelectionEvents(SelectionChangedEventArgs e) foreach (DateTime date in e.RemovedItems) { DateTimeAutomationPeer peer = GetOrCreateDateTimeAutomationPeer(date, CalendarMode.Month); - if (peer != null) - { - peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); - } + peer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridAutomationPeer.cs index 94fa409237d..926d1c6b29e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -329,10 +329,7 @@ internal void RaiseAutomationCellSelectedEvent(SelectedCellsChangedEventArgs e) this.OwningDataGrid.SelectedCells.Count == 1 && e.AddedCells.Count == 1) { DataGridCellItemAutomationPeer cellPeer = GetCellItemPeer(e.AddedCells[0]); - if (cellPeer != null) - { - cellPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); - } + cellPeer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } else { @@ -342,10 +339,7 @@ internal void RaiseAutomationCellSelectedEvent(SelectedCellsChangedEventArgs e) for (i = 0; i < e.AddedCells.Count; i++) { DataGridCellItemAutomationPeer cellPeer = GetCellItemPeer(e.AddedCells[i]); - if (cellPeer != null) - { - cellPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); - } + cellPeer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); } } @@ -354,10 +348,7 @@ internal void RaiseAutomationCellSelectedEvent(SelectedCellsChangedEventArgs e) for (i = 0; i < e.RemovedCells.Count; i++) { DataGridCellItemAutomationPeer cellPeer = GetCellItemPeer(e.RemovedCells[i]); - if (cellPeer != null) - { - cellPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); - } + cellPeer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } } @@ -368,10 +359,7 @@ internal void RaiseAutomationCellSelectedEvent(SelectedCellsChangedEventArgs e) internal void RaiseAutomationRowInvokeEvents(DataGridRow row) { DataGridItemAutomationPeer dataGridItemAutomationPeer = FindOrCreateItemAutomationPeer(row.Item) as DataGridItemAutomationPeer; - if (dataGridItemAutomationPeer != null) - { - dataGridItemAutomationPeer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); - } + dataGridItemAutomationPeer?.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } // This method is called from DataGrid.OnBeginningEdit/OnCommittingEdit/OnCancelingEdit @@ -382,10 +370,7 @@ internal void RaiseAutomationCellInvokeEvents(DataGridColumn column, DataGridRow if (dataGridItemAutomationPeer != null) { DataGridCellItemAutomationPeer cellPeer = dataGridItemAutomationPeer.GetOrCreateCellItemPeer(column); - if (cellPeer != null) - { - cellPeer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); - } + cellPeer?.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } } @@ -402,10 +387,7 @@ internal void RaiseAutomationSelectionEvents(SelectionChangedEventArgs e) numSelected == 1 && numAdded == 1) { ItemAutomationPeer peer = FindOrCreateItemAutomationPeer(this.OwningDataGrid.SelectedItem); - if (peer != null) - { - peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); - } + peer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } else { @@ -415,10 +397,7 @@ internal void RaiseAutomationSelectionEvents(SelectionChangedEventArgs e) for (i = 0; i < e.AddedItems.Count; i++) { ItemAutomationPeer peer = FindOrCreateItemAutomationPeer(e.AddedItems[i]); - if (peer != null) - { - peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); - } + peer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); } } @@ -427,10 +406,7 @@ internal void RaiseAutomationSelectionEvents(SelectionChangedEventArgs e) for (i = 0; i < e.RemovedItems.Count; i++) { ItemAutomationPeer peer = FindOrCreateItemAutomationPeer(e.RemovedItems[i]); - if (peer != null) - { - peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); - } + peer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridCellItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridCellItemAutomationPeer.cs index 0be0e9914b3..b78e5e18967 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridCellItemAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridCellItemAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -501,10 +501,7 @@ override internal bool IsDataItemAutomationPeer() override internal void AddToParentProxyWeakRefCache() { DataGridItemAutomationPeer owningItemPeer = this.OwningItemPeer; - if (owningItemPeer != null) - { - owningItemPeer.AddProxyToWeakRefStorage(this.ElementProxyWeakReference, this); - } + owningItemPeer?.AddProxyToWeakRefStorage(this.ElementProxyWeakReference, this); } @@ -850,7 +847,7 @@ private DataGridCell OwningCell get { DataGrid dataGrid = this.OwningDataGrid; - return (dataGrid != null) ? dataGrid.TryFindCell(Item, _column) : null; + return dataGrid?.TryFindCell(Item, _column); } } @@ -894,7 +891,7 @@ internal DataGridColumn Column internal object Item { - get { return (_item == null) ? null : _item.Target; } + get { return _item?.Target; } } private DataGridItemAutomationPeer OwningItemPeer diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridColumnHeadersPresenterAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridColumnHeadersPresenterAutomationPeer.cs index ce15cd50be2..3a9738b3303 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridColumnHeadersPresenterAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridColumnHeadersPresenterAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -110,7 +110,7 @@ protected override List GetChildrenCore() } // If the peer is null or dataItem.Header has changed, create a new peer. - object dataItemHeader = dataItem == null ? null : dataItem.Header; + object dataItemHeader = dataItem?.Header; if (peer == null || !ItemsControl.EqualsEx(peer.Item, dataItemHeader)) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridItemAutomationPeer.cs index 0b8189360b4..05ce4de0ad9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridItemAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridItemAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -573,7 +573,7 @@ internal AutomationPeer RowHeaderAutomationPeer get { DataGridRowAutomationPeer owningRowPeer = GetWrapperPeer() as DataGridRowAutomationPeer; - return (owningRowPeer != null) ? owningRowPeer.RowHeaderAutomationPeer : null; + return owningRowPeer?.RowHeaderAutomationPeer; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DateTimeAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DateTimeAutomationPeer.cs index 4f9ae3d6660..939fce1be63 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DateTimeAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DateTimeAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -905,10 +905,7 @@ override internal bool IsDataItemAutomationPeer() override internal void AddToParentProxyWeakRefCache() { CalendarAutomationPeer owningCalendarPeer = FrameworkElementAutomationPeer.CreatePeerForElement(OwningCalendar) as CalendarAutomationPeer; - if (owningCalendarPeer != null) - { - owningCalendarPeer.AddProxyToWeakRefStorage(this.ElementProxyWeakReference, this); - } + owningCalendarPeer?.AddProxyToWeakRefStorage(this.ElementProxyWeakReference, this); } #region Private Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentAutomationPeer.cs index e1567e1f150..d04c7c15442 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -217,7 +217,7 @@ private Rect CalculateBoundingRect(bool clipToVisible, out UIElement uiScope) if (Owner is IServiceProvider) { ITextContainer textContainer = ((IServiceProvider)Owner).GetService(typeof(ITextContainer)) as ITextContainer; - ITextView textView = (textContainer != null) ? textContainer.TextView : null; + ITextView textView = textContainer?.TextView; if (textView != null) { // Make sure TextView is updated diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentViewerBaseAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentViewerBaseAutomationPeer.cs index 5aec83c7fb5..59c59e95ec1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentViewerBaseAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentViewerBaseAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -68,10 +68,7 @@ protected override List GetChildrenCore() AutomationPeer documentPeer = GetDocumentAutomationPeer(); if (_documentPeer != documentPeer) { - if (_documentPeer != null) - { - _documentPeer.OnDisconnected(); - } + _documentPeer?.OnDisconnected(); _documentPeer = documentPeer as DocumentAutomationPeer; } if (documentPeer != null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FlowDocumentReaderAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FlowDocumentReaderAutomationPeer.cs index 45fd37d0c11..805616833e1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FlowDocumentReaderAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FlowDocumentReaderAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -63,10 +63,7 @@ protected override List GetChildrenCore() AutomationPeer documentPeer = ContentElementAutomationPeer.CreatePeerForElement(document); if (_documentPeer != documentPeer) { - if (_documentPeer != null) - { - _documentPeer.OnDisconnected(); - } + _documentPeer?.OnDisconnected(); _documentPeer = documentPeer as DocumentAutomationPeer; } if (documentPeer != null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FlowDocumentScrollViewerAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FlowDocumentScrollViewerAutomationPeer.cs index 694ab23a4f4..aaa0a855c6b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FlowDocumentScrollViewerAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FlowDocumentScrollViewerAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -93,10 +93,7 @@ protected override List GetChildrenCore() AutomationPeer documentPeer = ContentElementAutomationPeer.CreatePeerForElement(document); if (_documentPeer != documentPeer) { - if (_documentPeer != null) - { - _documentPeer.OnDisconnected(); - } + _documentPeer?.OnDisconnected(); _documentPeer = documentPeer as DocumentAutomationPeer; } if (documentPeer != null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridViewAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridViewAutomationPeer.cs index f1e215587a9..e32af2fdb51 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridViewAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridViewAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -201,10 +201,7 @@ IRawElementProviderSimple IGridProvider.GetItem(int row, int column) if (lvi == null) { VirtualizingPanel itemsHost = _listview.ItemsHost as VirtualizingPanel; - if (itemsHost != null) - { - itemsHost.BringIndexIntoView(row); - } + itemsHost?.BringIndexIntoView(row); lvi = _listview.ItemContainerGenerator.ContainerFromIndex(row) as ListViewItem; @@ -259,10 +256,7 @@ private void OnColumnCollectionChanged(object sender, NotifyCollectionChangedEve { ListViewAutomationPeer peer = UIElementAutomationPeer.FromElement(_listview) as ListViewAutomationPeer; Invariant.Assert(peer != null); - if (peer != null) - { - peer.RaisePropertyChangedEvent(GridPatternIdentifiers.ColumnCountProperty, _oldColumnsCount, _owner.Columns.Count); - } + peer?.RaisePropertyChangedEvent(GridPatternIdentifiers.ColumnCountProperty, _oldColumnsCount, _owner.Columns.Count); } _oldColumnsCount = _owner.Columns.Count; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GroupItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GroupItemAutomationPeer.cs index bf60886bcc7..296a1711995 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GroupItemAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GroupItemAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -172,10 +172,7 @@ protected override List GetChildrenCore() if (itemsControlAP.RecentlyRealizedPeers.Count > 0 && this.AncestorsInvalid) { GroupItemAutomationPeer groupItemPeer = peer as GroupItemAutomationPeer; - if (groupItemPeer != null) - { - groupItemPeer.InvalidateGroupItemPeersContainingRecentlyRealizedPeers(itemsControlAP.RecentlyRealizedPeers); - } + groupItemPeer?.InvalidateGroupItemPeersContainingRecentlyRealizedPeers(itemsControlAP.RecentlyRealizedPeers); } } else diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemAutomationPeer.cs index 5b5be0b384a..46fb8cb234a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -162,10 +162,7 @@ override internal bool IsDataItemAutomationPeer() override internal void AddToParentProxyWeakRefCache() { ItemsControlAutomationPeer itemsControlAutomationPeer = ItemsControlAutomationPeer; - if(itemsControlAutomationPeer != null) - { - itemsControlAutomationPeer.AddProxyToWeakRefStorage(this.ElementProxyWeakReference, this); - } + itemsControlAutomationPeer?.AddProxyToWeakRefStorage(this.ElementProxyWeakReference, this); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs index 42bf331eaf9..5e4b857ddc5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -94,10 +94,7 @@ protected override List GetChildrenCore() if (_recentlyRealizedPeers != null && _recentlyRealizedPeers.Count > 0 && this.AncestorsInvalid) { GroupItemAutomationPeer groupItemPeer = peer as GroupItemAutomationPeer; - if (groupItemPeer != null) - { - groupItemPeer.InvalidateGroupItemPeersContainingRecentlyRealizedPeers(_recentlyRealizedPeers); - } + groupItemPeer?.InvalidateGroupItemPeersContainingRecentlyRealizedPeers(_recentlyRealizedPeers); } } else @@ -213,10 +210,7 @@ internal ItemAutomationPeer ReusePeerForItem(ItemAutomationPeer peer, object ite } } - if (peer != null) - { - peer.ReuseForItem(item); - } + peer?.ReuseForItem(item); return peer; } @@ -380,10 +374,7 @@ protected virtual internal ItemAutomationPeer FindOrCreateItemAutomationPeer(obj { peer = CreateItemAutomationPeer(item); - if (peer != null) - { - peer.TrySetParentInfo(this); - } + peer?.TrySetParentInfo(this); } if (peer != null) @@ -424,7 +415,7 @@ internal RecyclableWrapper GetRecyclableWrapperPeer(object item) return _recyclableWrapperCache; } - // UpdateChildrenIntenal is called with ItemsInvalidateLimit to ensure we don’t fire unnecessary structure change events when items are just scrolled in/out of view in case of + // UpdateChildrenIntenal is called with ItemsInvalidateLimit to ensure we don’t fire unnecessary structure change events when items are just scrolled in/out of view in case of // virtualized controls. override internal IDisposable UpdateChildren() { @@ -572,11 +563,9 @@ public void Clear() _usesHashCode = false; _count = 0; - if (_hashtable != null) - _hashtable.Clear(); + _hashtable?.Clear(); - if (_list != null) - _list.Clear(); + _list?.Clear(); } public T this[object item] diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ListBoxItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ListBoxItemAutomationPeer.cs index 08127c478f7..222090cd97b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ListBoxItemAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ListBoxItemAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -59,8 +59,7 @@ void IScrollItemProvider.ScrollIntoView() else { ComboBoxAutomationPeer parentPeer = ItemsControlAutomationPeer as ComboBoxAutomationPeer; - if(parentPeer != null) - parentPeer.ScrollItemIntoView(Item); + parentPeer?.ScrollItemIntoView(Item); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/SelectorAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/SelectorAutomationPeer.cs index d2fac7507b8..b31c36396f5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/SelectorAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/SelectorAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -147,10 +147,7 @@ internal void RaiseSelectionEvents(SelectionChangedEventArgs e) if (numSelected == 1 && numAdded == 1) { SelectorItemAutomationPeer peer = FindOrCreateItemAutomationPeer(owner._selectedItems[0].Item) as SelectorItemAutomationPeer; - if(peer != null) - { - peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); - } + peer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } else { @@ -168,20 +165,14 @@ internal void RaiseSelectionEvents(SelectionChangedEventArgs e) { SelectorItemAutomationPeer peer = FindOrCreateItemAutomationPeer(e.AddedItems[i]) as SelectorItemAutomationPeer; - if (peer != null) - { - peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); - } + peer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); } for (i = 0; i < numRemoved; i++) { SelectorItemAutomationPeer peer = FindOrCreateItemAutomationPeer(e.RemovedItems[i]) as SelectorItemAutomationPeer; - if (peer != null) - { - peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); - } + peer?.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/TreeViewDataItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/TreeViewDataItemAutomationPeer.cs index cf3bd49a0c1..8977689490f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/TreeViewDataItemAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/TreeViewDataItemAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -65,10 +65,7 @@ override internal AutomationPeer GetWrapperPeer() { AutomationPeer wrapperPeer = base.GetWrapperPeer(); TreeViewItemAutomationPeer treeViewItemWrapperPeer = wrapperPeer as TreeViewItemAutomationPeer; - if (treeViewItemWrapperPeer != null) - { - treeViewItemWrapperPeer.AddDataPeerInfo(this); - } + treeViewItemWrapperPeer?.AddDataPeerInfo(this); return wrapperPeer; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/TreeViewItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/TreeViewItemAutomationPeer.cs index 6a2f3ac63fc..09b832ff809 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/TreeViewItemAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/TreeViewItemAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -169,10 +169,7 @@ protected override internal ItemAutomationPeer FindOrCreateItemAutomationPeer(ob { peer = CreateItemAutomationPeer(item); - if(peer != null) - { - peer.TrySetParentInfo(parentPeer); - } + peer?.TrySetParentInfo(parentPeer); } if(peer != null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ComponentResourceKey.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ComponentResourceKey.cs index 1ce9d55f971..1f9a6c4f438 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ComponentResourceKey.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ComponentResourceKey.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -66,7 +66,7 @@ public override Assembly Assembly { get { - return (_typeInTargetAssembly != null) ? _typeInTargetAssembly.Assembly : null; + return _typeInTargetAssembly?.Assembly; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/AdornedElementPlaceholder.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/AdornedElementPlaceholder.cs index f27b3a84d41..505af009a3b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/AdornedElementPlaceholder.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/AdornedElementPlaceholder.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -189,8 +189,7 @@ protected override Size MeasureOverride(Size constraint) Size desiredSize = AdornedElement.RenderSize; UIElement child = Child; - if (child != null) - child.Measure(desiredSize); + child?.Measure(desiredSize); return desiredSize; } @@ -204,8 +203,7 @@ protected override Size ArrangeOverride(Size arrangeBounds) { UIElement child = Child; - if (child != null) - child.Arrange(new Rect(arrangeBounds)); + child?.Arrange(new Rect(arrangeBounds)); return arrangeBounds; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Button.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Button.cs index cb124b56633..93cdda10e27 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Button.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Button.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -250,8 +250,7 @@ protected override void OnClick() if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { AutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(this); - if (peer != null) - peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); + peer?.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } // base.OnClick should be called first. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Calendar.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Calendar.cs index 00c94607c9d..0328a18aa16 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Calendar.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Calendar.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1049,10 +1049,7 @@ internal void OnSelectedDatesCollectionChanged(SelectionChangedEventArgs e) AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { CalendarAutomationPeer peer = FrameworkElementAutomationPeer.FromElement(this) as CalendarAutomationPeer; - if (peer != null) - { - peer.RaiseSelectionEvents(e); - } + peer?.RaiseSelectionEvents(e); } CoerceFromSelection(); @@ -1212,10 +1209,7 @@ private void OnSelectedYearChanged(DateTime? selectedYear) internal void FocusDate(DateTime date) { - if (MonthControl != null) - { - MonthControl.FocusDate(date); - } + MonthControl?.FocusDate(date); } @@ -1250,7 +1244,7 @@ private bool ProcessCalendarKey(KeyEventArgs e) { // If a blackout day is inactive, when clicked on it, the previous inactive day which is not a blackout day can get the focus. // In this case we should allow keyboard functions on that inactive day - CalendarDayButton currentDayButton = (MonthControl != null) ? MonthControl.GetCalendarDayButton(this.CurrentDate) : null; + CalendarDayButton currentDayButton = MonthControl?.GetCalendarDayButton(this.CurrentDate); if (DateTimeHelper.CompareYearMonth(this.CurrentDate, this.DisplayDateInternal) != 0 && currentDayButton != null && !currentDayButton.IsInactive) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Canvas.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Canvas.cs index 7731b8b6049..45ea1afc9de 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Canvas.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Canvas.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -188,8 +188,7 @@ private static void OnPositioningChanged(DependencyObject d, DependencyPropertyC if(uie != null) { Canvas p = VisualTreeHelper.GetParent(uie) as Canvas; - if(p != null) - p.InvalidateArrange(); + p?.InvalidateArrange(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBox.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBox.cs index bc792c20ac2..ae4e9d657a8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBox.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBox.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -213,10 +213,7 @@ private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyProper // Fire accessibility event ComboBoxAutomationPeer peer = UIElementAutomationPeer.FromElement(comboBox) as ComboBoxAutomationPeer; - if(peer != null) - { - peer.RaiseExpandCollapseAutomationEvent(oldValue, newValue); - } + peer?.RaiseExpandCollapseAutomationEvent(oldValue, newValue); if (newValue) { @@ -236,10 +233,7 @@ private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyProper ComboBox cb = (ComboBox)arg; cb.UpdateSelectionBoxItem(); - if (cb._clonedElement != null) - { - cb._clonedElement.CoerceValue(FrameworkElement.FlowDirectionProperty); - } + cb._clonedElement?.CoerceValue(FrameworkElement.FlowDirectionProperty); return null; }, @@ -572,8 +566,7 @@ protected override void OnSelectionChanged(SelectionChangedEventArgs e) || AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection) ) { ComboBoxAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(this) as ComboBoxAutomationPeer; - if (peer != null) - peer.RaiseSelectionEvents(e); + peer?.RaiseSelectionEvents(e); } } @@ -617,8 +610,7 @@ private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedE ComboBoxAutomationPeer peer = UIElementAutomationPeer.FromElement(cb) as ComboBoxAutomationPeer; // Raise the propetyChangeEvent for Value if Automation Peer exist, the new Value must // be the one in SelctionBoxItem(selected value is the one user will care about) - if (peer != null) - peer.RaiseValuePropertyChangedEvent((string)e.OldValue, (string)e.NewValue); + peer?.RaiseValuePropertyChangedEvent((string)e.OldValue, (string)e.NewValue); cb.TextUpdated((string)e.NewValue, false); } @@ -1948,18 +1940,12 @@ private ItemInfo HighlightedInfo set { ComboBoxItem cbi = (_highlightedInfo != null) ? _highlightedInfo.Container as ComboBoxItem : null; - if (cbi != null) - { - cbi.SetIsHighlighted(false); - } + cbi?.SetIsHighlighted(false); _highlightedInfo = value; cbi = (_highlightedInfo != null) ? _highlightedInfo.Container as ComboBoxItem : null; - if (cbi != null) - { - cbi.SetIsHighlighted(true); - } + cbi?.SetIsHighlighted(true); CoerceValue(IsSelectionBoxHighlightedProperty); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBoxItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBoxItem.cs index 5141616b510..2b042c17c7d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBoxItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBoxItem.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -97,10 +97,7 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) ComboBox parent = ParentComboBox; - if (parent != null) - { - parent.NotifyComboBoxItemMouseDown(this); - } + parent?.NotifyComboBoxItemMouseDown(this); base.OnMouseLeftButtonDown(e); } @@ -115,10 +112,7 @@ protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) ComboBox parent = ParentComboBox; - if (parent != null) - { - parent.NotifyComboBoxItemMouseUp(this); - } + parent?.NotifyComboBoxItemMouseUp(this); base.OnMouseLeftButtonUp(e); } @@ -133,10 +127,7 @@ protected override void OnMouseEnter(MouseEventArgs e) ComboBox parent = ParentComboBox; - if (parent != null) - { - parent.NotifyComboBoxItemEnter(this); - } + parent?.NotifyComboBoxItemEnter(this); base.OnMouseEnter(e); } @@ -183,10 +174,7 @@ protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e) ComboBox parent = ParentComboBox; - if (parent != null) - { - parent.NotifyComboBoxItemEnter(this); - } + parent?.NotifyComboBoxItemEnter(this); base.OnGotKeyboardFocus(e); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Control.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Control.cs index 7c95677571a..6460b994035 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Control.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Control.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -674,10 +674,7 @@ internal static void OnVisualStatePropertyChanged(DependencyObject d, Dependency // Due to inherited properties, its safer not to cast to control because this might get fired for // non-controls. var control = d as Control; - if (control != null) - { - control.UpdateVisualState(); - } + control?.UpdateVisualState(); } /// @@ -718,10 +715,7 @@ protected override Size ArrangeOverride(Size arrangeBounds) if (count>0) { UIElement child = (UIElement)(this.GetVisualChild(0)); - if (child != null) - { - child.Arrange(new Rect(arrangeBounds)); - } + child?.Arrange(new Rect(arrangeBounds)); } return arrangeBounds; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CustomDictionarySources.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CustomDictionarySources.cs index 452cafb76ae..2a64bbbb25f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CustomDictionarySources.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CustomDictionarySources.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -96,10 +96,7 @@ void IList.Insert(int index, Uri item) ValidateUri(item); _uriList.Insert(index, item); - if (Speller != null) - { - Speller.OnDictionaryUriAdded(item); - } + Speller?.OnDictionaryUriAdded(item); } void IList.RemoveAt(int index) @@ -107,10 +104,7 @@ void IList.RemoveAt(int index) Uri uri = _uriList[index]; _uriList.RemoveAt(index); - if (Speller != null) - { - Speller.OnDictionaryUriRemoved(uri); - } + Speller?.OnDictionaryUriRemoved(uri); } /// @@ -130,15 +124,9 @@ Uri IList.this[int index] { ValidateUri(value); Uri oldUri = _uriList[index]; - if (Speller != null) - { - Speller.OnDictionaryUriRemoved(oldUri); - } + Speller?.OnDictionaryUriRemoved(oldUri); _uriList[index] = value; - if (Speller != null) - { - Speller.OnDictionaryUriAdded(value); - } + Speller?.OnDictionaryUriAdded(value); } } @@ -159,19 +147,13 @@ void ICollection.Add(Uri item) _uriList.Add(item); } - if (Speller != null) - { - Speller.OnDictionaryUriAdded(item); - } + Speller?.OnDictionaryUriAdded(item); } void ICollection.Clear() { _uriList.Clear(); - if (Speller != null) - { - Speller.OnDictionaryUriCollectionCleared(); - } + Speller?.OnDictionaryUriCollectionCleared(); } bool ICollection.Contains(Uri item) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs index d97b7fb193b..e2e3988224f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -617,10 +617,7 @@ internal void NotifyPropertyChanged(DependencyObject d, string propertyName, Dep if (row != null) { var cellsPresenter = row.CellsPresenter; - if (cellsPresenter != null) - { - cellsPresenter.InvalidateDataGridCellsPanelMeasureAndArrange(); - } + cellsPresenter?.InvalidateDataGridCellsPanelMeasureAndArrange(); } } } @@ -1160,10 +1157,7 @@ internal static object DelayedOnLoadingRowDetails(object arg) var row = (DataGridRow)arg; var dataGrid = row.DataGridOwner; - if (dataGrid != null) - { - dataGrid.OnLoadingRowDetailsWrapper(row); - } + dataGrid?.OnLoadingRowDetailsWrapper(row); return null; } @@ -1347,10 +1341,7 @@ public void ClearDetailsVisibilityForItem(object item) _itemAttachedStorage.ClearValue(item, DataGridRow.DetailsVisibilityProperty); var row = (DataGridRow)ItemContainerGenerator.ContainerFromItem(item); - if (row != null) - { - row.ClearValue(DataGridRow.DetailsVisibilityProperty); - } + row?.ClearValue(DataGridRow.DetailsVisibilityProperty); } internal DataGridItemAttachedStorage ItemAttachedStorage @@ -2256,10 +2247,7 @@ protected virtual void OnExecutedBeginEdit(ExecutedRoutedEventArgs e) EditRowItem(cell.RowDataItem); var bindingGroup = cell.RowOwner.BindingGroup; - if (bindingGroup != null) - { - bindingGroup.BeginEdit(); - } + bindingGroup?.BeginEdit(); _editingRowInfo = ItemInfoFromContainer(cell.RowOwner); } @@ -2449,10 +2437,7 @@ protected virtual void OnRowEditEnding(DataGridRowEditEndingEventArgs e) if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { DataGridAutomationPeer peer = DataGridAutomationPeer.FromElement(this) as DataGridAutomationPeer; - if (peer != null) - { - peer.RaiseAutomationRowInvokeEvents(e.Row); - } + peer?.RaiseAutomationRowInvokeEvents(e.Row); } } @@ -2476,10 +2461,7 @@ protected virtual void OnCellEditEnding(DataGridCellEditEndingEventArgs e) if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { DataGridAutomationPeer peer = DataGridAutomationPeer.FromElement(this) as DataGridAutomationPeer; - if (peer != null) - { - peer.RaiseAutomationCellInvokeEvents(e.Column, e.Row); - } + peer?.RaiseAutomationCellInvokeEvents(e.Column, e.Row); } } @@ -2546,10 +2528,7 @@ protected virtual void OnExecutedCancelEdit(ExecutedRoutedEventArgs e) if (cancelAllowed) { var bindingGroup = cell.RowOwner.BindingGroup; - if (bindingGroup != null) - { - bindingGroup.CancelEdit(); - } + bindingGroup?.CancelEdit(); CancelRowItem(); } @@ -2948,17 +2927,14 @@ private static void OnCurrentCellChanged(DependencyObject d, DependencyPropertyC if (oldCellContainer != cell) { - if (oldCellContainer != null) - { - oldCellContainer.NotifyCurrentCellContainerChanged(); - } + oldCellContainer?.NotifyCurrentCellContainerChanged(); cell.NotifyCurrentCellContainerChanged(); } } - else if (oldCellContainer != null) + else { - oldCellContainer.NotifyCurrentCellContainerChanged(); + oldCellContainer?.NotifyCurrentCellContainerChanged(); } } @@ -3121,10 +3097,7 @@ protected virtual void OnBeginningEdit(DataGridBeginningEditEventArgs e) if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { DataGridAutomationPeer peer = DataGridAutomationPeer.FromElement(this) as DataGridAutomationPeer; - if (peer != null) - { - peer.RaiseAutomationCellInvokeEvents(e.Column, e.Row); - } + peer?.RaiseAutomationCellInvokeEvents(e.Column, e.Row); } } @@ -3806,10 +3779,7 @@ private void UpdateNewItemPlaceholder(bool isAddingNewItem) // Make sure the newItemPlaceholderRow reflects the correct visiblity DataGridRow newItemPlaceholderRow = (DataGridRow)ItemContainerGenerator.ContainerFromItem(CollectionView.NewItemPlaceholder); - if (newItemPlaceholderRow != null) - { - newItemPlaceholderRow.CoerceValue(VisibilityProperty); - } + newItemPlaceholderRow?.CoerceValue(VisibilityProperty); } private void SetCurrentItemToPlaceholder() @@ -4308,10 +4278,7 @@ protected virtual void OnSelectedCellsChanged(SelectedCellsChangedEventArgs e) AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { DataGridAutomationPeer peer = DataGridAutomationPeer.FromElement(this) as DataGridAutomationPeer; - if (peer != null) - { - peer.RaiseAutomationCellSelectedEvent(e); - } + peer?.RaiseAutomationCellSelectedEvent(e); } } @@ -4561,10 +4528,7 @@ protected override void OnSelectionChanged(SelectionChangedEventArgs e) AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { DataGridAutomationPeer peer = DataGridAutomationPeer.FromElement(this) as DataGridAutomationPeer; - if (peer != null) - { - peer.RaiseAutomationSelectionEvents(e); - } + peer?.RaiseAutomationSelectionEvents(e); } base.OnSelectionChanged(e); @@ -4647,10 +4611,7 @@ private void UpdateIsSelected(VirtualizedCellInfoCollection cells, bool isSelect foreach (DataGridCellInfo cellInfo in cells) { DataGridCell cell = TryFindCell(cellInfo); - if (cell != null) - { - cell.SyncIsSelected(isSelected); - } + cell?.SyncIsSelected(isSelected); } } } @@ -4959,10 +4920,7 @@ private void MakeFullRowSelection(ItemInfo info, bool allowsExtendSelect, bool a } IDisposable d = enumerator as IDisposable; - if (d != null) - { - d.Dispose(); - } + d?.Dispose(); _selectedCells.AddRegion(startIndex, 0, endIndex - startIndex + 1, _columns.Count); } @@ -6013,10 +5971,7 @@ private void OnEnterKeyDown(KeyEventArgs e) // When the new item jumped to the bottom, CurrentCell doesn't actually change, // but there is a new container. currentCellContainer = CurrentCellContainer; - if (currentCellContainer != null) - { - currentCellContainer.Focus(); - } + currentCellContainer?.Focus(); } } } @@ -6231,9 +6186,9 @@ private void OnPageUpOrDownKeyDown(KeyEventArgs e) } } } - else if (targetElement != null) + else { - targetElement.Focus(); + targetElement?.Focus(); } } } @@ -6890,10 +6845,7 @@ public void TrackValue() if (dataGridItemAutomationPeer != null) { DataGridCellItemAutomationPeer cellPeer = dataGridItemAutomationPeer.GetOrCreateCellItemPeer(column); - if (cellPeer != null) - { - cellPeer.RaisePropertyChangedEvent(ValuePatternIdentifiers.ValueProperty, _value, newValue); - } + cellPeer?.RaisePropertyChangedEvent(ValuePatternIdentifiers.ValueProperty, _value, newValue); } } } @@ -7592,10 +7544,7 @@ private void ClearSortDescriptionsOnItemsSourceChange() Items.SortDescriptions.Clear(); _sortingStarted = false; List groupingSortDescriptionIndices = GroupingSortDescriptionIndices; - if (groupingSortDescriptionIndices != null) - { - groupingSortDescriptionIndices.Clear(); - } + groupingSortDescriptionIndices?.Clear(); foreach (DataGridColumn column in Columns) { column.SortDirection = null; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCell.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCell.cs index d434e939c17..ece9f7c5bcb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCell.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCell.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -178,10 +178,7 @@ public DataGridColumn Column private static void OnColumnChanged(object sender, DependencyPropertyChangedEventArgs e) { DataGridCell cell = sender as DataGridCell; - if (cell != null) - { - cell.OnColumnChanged((DataGridColumn)e.OldValue, (DataGridColumn)e.NewValue); - } + cell?.OnColumnChanged((DataGridColumn)e.OldValue, (DataGridColumn)e.NewValue); } /// @@ -579,11 +576,8 @@ internal void BeginEdit(RoutedEventArgs e) IsEditing = true; DataGridColumn column = Column; - if (column != null) - { - // Ask the column to store the original value - column.BeginEdit(Content as FrameworkElement, e); - } + // Ask the column to store the original value + column?.BeginEdit(Content as FrameworkElement, e); RaisePreparingCellForEdit(e); } @@ -593,11 +587,8 @@ internal void CancelEdit() Debug.Assert(IsEditing, "Should not call CancelEdit when IsEditing is false."); DataGridColumn column = Column; - if (column != null) - { - // Ask the column to restore the original value - column.CancelEdit(Content as FrameworkElement); - } + // Ask the column to restore the original value + column?.CancelEdit(Content as FrameworkElement); IsEditing = false; } @@ -671,13 +662,10 @@ private static void OnIsSelectedChanged(object sender, DependencyPropertyChanged if (!cell._syncingIsSelected) { DataGrid dataGrid = cell.DataGridOwner; - if (dataGrid != null) - { - // Notify the DataGrid that a cell's IsSelected property changed - // in case it was done programmatically instead of by the - // DataGrid itself. - dataGrid.CellIsSelectedChanged(cell, isSelected); - } + // Notify the DataGrid that a cell's IsSelected property changed + // in case it was done programmatically instead of by the + // DataGrid itself. + dataGrid?.CellIsSelectedChanged(cell, isSelected); } cell.RaiseSelectionChangedEvent(isSelected); @@ -929,11 +917,8 @@ private void OnAnyMouseLeftButtonDown(MouseButtonEventArgs e) } DataGrid dataGridOwner = DataGridOwner; - if (dataGridOwner != null) - { - // Let the DataGrid process selection - dataGridOwner.HandleSelectionForCellInput(this, /* startDragging = */ Mouse.Captured == null, /* allowsExtendSelect = */ true, /* allowsMinimalSelect = */ true); - } + // Let the DataGrid process selection + dataGridOwner?.HandleSelectionForCellInput(this, /* startDragging = */ Mouse.Captured == null, /* allowsExtendSelect = */ true, /* allowsMinimalSelect = */ true); e.Handled = true; } @@ -1031,10 +1016,7 @@ protected override void OnMouseUp(MouseButtonEventArgs e) private void SendInputToColumn(InputEventArgs e) { var column = Column; - if (column != null) - { - column.OnInput(e); - } + column?.OnInput(e); } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellInfo.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellInfo.cs index 3916267624a..bae2e5001be 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellInfo.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellInfo.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -131,7 +131,7 @@ internal static DataGridCellInfo CreatePossiblyPartialCellInfo(object item, Data /// public object Item { - get { return (_info != null) ? _info.Item : null; } + get { return _info?.Item; } } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs index 730afef12b4..54f2a0f166c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -81,8 +81,7 @@ protected override Size MeasureOverride(Size constraint) // This makes sure that the ItemsPresenter and the DatagridCellsPresenter is invalidated even if this is an arrange pass. this.ParentPresenter.InvalidateMeasure(); UIElement parent = VisualTreeHelper.GetParent(this) as UIElement; - if (parent != null) - parent.InvalidateMeasure(); + parent?.InvalidateMeasure(); } return measureSize; @@ -1309,17 +1308,11 @@ private void FinishArrange(ArrangeState arrangeState) } // Remove the clip on previous clipped child - if (arrangeState.OldClippedChild != null) - { - arrangeState.OldClippedChild.CoerceValue(ClipProperty); - } + arrangeState.OldClippedChild?.CoerceValue(ClipProperty); // Add the clip on new child to be clipped for the sake of frozen columns. _clippedChildForFrozenBehaviour = arrangeState.NewClippedChild; - if (_clippedChildForFrozenBehaviour != null) - { - _clippedChildForFrozenBehaviour.CoerceValue(ClipProperty); - } + _clippedChildForFrozenBehaviour?.CoerceValue(ClipProperty); } private void SetDataGridCellPanelWidth(IList children, double newWidth) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumn.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumn.cs index 1f2ce9b181a..9c18f479edf 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumn.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumn.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -870,10 +870,7 @@ internal void NotifyPropertyChanged(DependencyObject d, DependencyPropertyChange // to the targets that need notification. DataGridColumn column = (DataGridColumn)d; DataGrid dataGridOwner = column.DataGridOwner; - if (dataGridOwner != null) - { - dataGridOwner.NotifyPropertyChanged(d, e, target); - } + dataGridOwner?.NotifyPropertyChanged(d, e, target); } } @@ -883,10 +880,7 @@ internal void NotifyPropertyChanged(DependencyObject d, DependencyPropertyChange /// protected void NotifyPropertyChanged(string propertyName) { - if (DataGridOwner != null) - { - DataGridOwner.NotifyPropertyChanged(this, propertyName, new DependencyPropertyChangedEventArgs(), DataGridNotificationTarget.RefreshCellContent); - } + DataGridOwner?.NotifyPropertyChanged(this, propertyName, new DependencyPropertyChangedEventArgs(), DataGridNotificationTarget.RefreshCellContent); } /// @@ -973,10 +967,7 @@ private static object OnCoerceDisplayIndex(DependencyObject d, object baseValue) { DataGridColumn column = (DataGridColumn)d; - if (column.DataGridOwner != null) - { - column.DataGridOwner.ValidateDisplayIndex(column, (int)baseValue); - } + column.DataGridOwner?.ValidateDisplayIndex(column, (int)baseValue); return baseValue; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnCollection.cs index 7707aa15a7f..2e019218977 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnCollection.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1052,10 +1052,7 @@ internal void InvalidateAverageColumnWidth() // size of the row presenter VirtualizingStackPanel vsp = (DataGridOwner == null) ? null : DataGridOwner.InternalItemsHost as VirtualizingStackPanel; - if (vsp != null) - { - vsp.ResetMaximumDesiredSize(); - } + vsp?.ResetMaximumDesiredSize(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs index 9849eb680ef..d6011646366 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -578,10 +578,7 @@ internal void OnRowResizeReset() if (cellsPresenter != null) { cellsPresenter.ClearValue(DataGridCellsPresenter.HeightProperty); - if (_owner != null) - { - _owner.ItemAttachedStorage.ClearValue(Item, DataGridCellsPresenter.HeightProperty); - } + _owner?.ItemAttachedStorage.ClearValue(Item, DataGridCellsPresenter.HeightProperty); } } @@ -597,10 +594,7 @@ internal void OnRowResizeReset() protected internal virtual void OnColumnsChanged(ObservableCollection columns, NotifyCollectionChangedEventArgs e) { DataGridCellsPresenter cellsPresenter = CellsPresenter; - if (cellsPresenter != null) - { - cellsPresenter.OnColumnsChanged(columns, e); - } + cellsPresenter?.OnColumnsChanged(columns, e); } #endregion @@ -795,10 +789,7 @@ private static void OnNotifyDetailsTemplatePropertyChanged(DependencyObject d, D if (row.DetailsLoaded && d.GetValue(e.Property) == e.NewValue) { - if (row.DataGridOwner != null) - { - row.DataGridOwner.OnUnloadingRowDetailsWrapper(row); - } + row.DataGridOwner?.OnUnloadingRowDetailsWrapper(row); if (e.NewValue != null) { // Invoke LoadingRowDetails, but only after the details template is expanded (so DetailsElement will be available). @@ -823,7 +814,7 @@ private static object DelayedRowDetailsVisibilityChanged(object arg) { var row = (DataGridRow)arg; var dataGrid = row.DataGridOwner; - var detailsElement = row.DetailsPresenter != null ? row.DetailsPresenter.DetailsElement : null; + var detailsElement = row.DetailsPresenter?.DetailsElement; if (dataGrid != null) { var detailsEventArgs = new DataGridRowDetailsEventArgs(row, detailsElement); @@ -933,10 +924,7 @@ internal void NotifyPropertyChanged(DependencyObject d, string propertyName, Dep if (DataGridHelper.ShouldNotifyDetailsPresenter(target)) { - if (DetailsPresenter != null) - { - DetailsPresenter.NotifyPropertyChanged(d, e); - } + DetailsPresenter?.NotifyPropertyChanged(d, e); } if (DataGridHelper.ShouldNotifyCellsPresenter(target) || @@ -944,10 +932,7 @@ internal void NotifyPropertyChanged(DependencyObject d, string propertyName, Dep DataGridHelper.ShouldRefreshCellContent(target)) { DataGridCellsPresenter cellsPresenter = CellsPresenter; - if (cellsPresenter != null) - { - cellsPresenter.NotifyPropertyChanged(d, propertyName, e, target); - } + cellsPresenter?.NotifyPropertyChanged(d, propertyName, e, target); } if (DataGridHelper.ShouldNotifyRowHeaders(target) && RowHeader != null) @@ -1010,15 +995,9 @@ private void SyncProperties(bool forcePrepareCells) RestoreAttachedItemValue(cellsPresenter, DataGridCellsPresenter.HeightProperty); } - if (DetailsPresenter != null) - { - DetailsPresenter.SyncProperties(); - } + DetailsPresenter?.SyncProperties(); - if (RowHeader != null) - { - RowHeader.SyncProperties(); - } + RowHeader?.SyncProperties(); } #endregion @@ -1090,13 +1069,10 @@ private static void OnIsSelectedChanged(object sender, DependencyPropertyChanged if (gridPeer != null) { DataGridItemAutomationPeer rowItemPeer = gridPeer.FindOrCreateItemAutomationPeer(row.DataContext) as DataGridItemAutomationPeer; - if (rowItemPeer != null) - { - rowItemPeer.RaisePropertyChangedEvent( + rowItemPeer?.RaisePropertyChangedEvent( System.Windows.Automation.SelectionItemPatternIdentifiers.IsSelectedProperty, (bool)e.OldValue, isSelected); - } } } @@ -1246,10 +1222,7 @@ protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutoma internal void ScrollCellIntoView(int index) { DataGridCellsPresenter cellsPresenter = CellsPresenter; - if (cellsPresenter != null) - { - cellsPresenter.ScrollCellIntoView(index); - } + cellsPresenter?.ScrollCellIntoView(index); } #endregion @@ -1262,10 +1235,7 @@ internal void ScrollCellIntoView(int index) protected override Size ArrangeOverride(Size arrangeBounds) { DataGrid dataGrid = DataGridOwner; - if (dataGrid != null) - { - dataGrid.QueueInvalidateCellsPanelHorizontalOffset(); - } + dataGrid?.QueueInvalidateCellsPanelHorizontalOffset(); return base.ArrangeOverride(arrangeBounds); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DatePicker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DatePicker.cs index 5b3bc2dadf5..a95de4fbedb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DatePicker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DatePicker.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -881,10 +881,7 @@ private void SetIsHandlerSuspended(DependencyProperty property, bool value) } else { - if (_isHandlerSuspended != null) - { - _isHandlerSuspended.Remove(property); - } + _isHandlerSuspended?.Remove(property); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Decorator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Decorator.cs index 565eff94bb2..33c6e3fa5f8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Decorator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Decorator.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -204,10 +204,7 @@ protected override Size MeasureOverride(Size constraint) protected override Size ArrangeOverride(Size arrangeSize) { UIElement child = Child; - if (child != null) - { - child.Arrange(new Rect(arrangeSize)); - } + child?.Arrange(new Rect(arrangeSize)); return (arrangeSize); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DeferredTextReference.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DeferredTextReference.cs index e56a8acab90..59f44a8a99e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DeferredTextReference.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DeferredTextReference.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -44,10 +44,7 @@ internal override object GetValue(BaseValueSourceInternal valueSource) string s = TextRangeBase.GetTextInternal(_textContainer.Start, _textContainer.End); TextBox tb = _textContainer.Parent as TextBox; - if (tb != null) - { - tb.OnDeferredTextReferenceResolved(this, s); - } + tb?.OnDeferredTextReferenceResolved(this, s); return s; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs index 2e8010f3622..93d1b4f9227 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -114,7 +114,7 @@ internal void OnBeforeLayout(Grid grid) LayoutWasUpdated = true; // defer verification for shared definitions - if (_sharedState != null) { _sharedState.EnsureDeferredValidation(grid); } + _sharedState?.EnsureDeferredValidation(grid); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DockPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DockPanel.cs index 398732c1897..b2662e24820 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DockPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DockPanel.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -122,10 +122,7 @@ private static void OnDockChanged(DependencyObject d, DependencyPropertyChangedE if(uie != null) { DockPanel p = VisualTreeHelper.GetParent(uie) as DockPanel; - if(p != null) - { - p.InvalidateMeasure(); - } + p?.InvalidateMeasure(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs index 5d88bd25b9a..a5ba7193848 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -123,10 +123,7 @@ public void FitToMaxPagesAcross(int pagesAcross) { if (ValidateMaxPagesAcross(pagesAcross)) { - if (_documentScrollInfo != null) - { - _documentScrollInfo.FitColumns(pagesAcross); - } + _documentScrollInfo?.FitColumns(pagesAcross); } else { @@ -920,10 +917,7 @@ protected override void OnBringIntoView(DependencyObject element, Rect rect, int protected override void OnPreviousPageCommand() { //Scroll to the previous row. - if (_documentScrollInfo != null) - { - _documentScrollInfo.ScrollToPreviousRow(); - } + _documentScrollInfo?.ScrollToPreviousRow(); } /// @@ -932,10 +926,7 @@ protected override void OnPreviousPageCommand() protected override void OnNextPageCommand() { //Scroll to the previous row. - if (_documentScrollInfo != null) - { - _documentScrollInfo.ScrollToNextRow(); - } + _documentScrollInfo?.ScrollToNextRow(); } /// @@ -944,10 +935,7 @@ protected override void OnNextPageCommand() protected override void OnFirstPageCommand() { //Scroll to the top of the document. - if (_documentScrollInfo != null) - { - _documentScrollInfo.MakePageVisible( 0 ); - } + _documentScrollInfo?.MakePageVisible( 0 ); } /// @@ -956,10 +944,7 @@ protected override void OnFirstPageCommand() protected override void OnLastPageCommand() { //Scroll to the bottom of the document. - if (_documentScrollInfo != null) - { - _documentScrollInfo.MakePageVisible( PageCount - 1 ); - } + _documentScrollInfo?.MakePageVisible( PageCount - 1 ); } /// @@ -986,10 +971,7 @@ protected override void OnGoToPageCommand(int pageNumber) /// protected virtual void OnViewThumbnailsCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.ViewThumbnails(); - } + _documentScrollInfo?.ViewThumbnails(); } /// @@ -997,10 +979,7 @@ protected virtual void OnViewThumbnailsCommand() /// protected virtual void OnFitToWidthCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.FitToPageWidth(); - } + _documentScrollInfo?.FitToPageWidth(); } /// @@ -1008,10 +987,7 @@ protected virtual void OnFitToWidthCommand() /// protected virtual void OnFitToHeightCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.FitToPageHeight(); - } + _documentScrollInfo?.FitToPageHeight(); } /// @@ -1019,10 +995,7 @@ protected virtual void OnFitToHeightCommand() /// protected virtual void OnFitToMaxPagesAcrossCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.FitColumns(MaxPagesAcross); - } + _documentScrollInfo?.FitColumns(MaxPagesAcross); } /// @@ -1033,10 +1006,7 @@ protected virtual void OnFitToMaxPagesAcrossCommand(int pagesAcross) { if (ValidateMaxPagesAcross(pagesAcross)) { - if (_documentScrollInfo != null) - { - _documentScrollInfo.FitColumns(pagesAcross); - } + _documentScrollInfo?.FitColumns(pagesAcross); } else { @@ -1070,10 +1040,7 @@ protected override void OnKeyDown(KeyEventArgs e) /// protected virtual void OnScrollPageUpCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.PageUp(); - } + _documentScrollInfo?.PageUp(); } /// @@ -1081,10 +1048,7 @@ protected virtual void OnScrollPageUpCommand() /// protected virtual void OnScrollPageDownCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.PageDown(); - } + _documentScrollInfo?.PageDown(); } /// @@ -1092,10 +1056,7 @@ protected virtual void OnScrollPageDownCommand() /// protected virtual void OnScrollPageLeftCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.PageLeft(); - } + _documentScrollInfo?.PageLeft(); } /// @@ -1103,10 +1064,7 @@ protected virtual void OnScrollPageLeftCommand() /// protected virtual void OnScrollPageRightCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.PageRight(); - } + _documentScrollInfo?.PageRight(); } /// @@ -1114,10 +1072,7 @@ protected virtual void OnScrollPageRightCommand() /// protected virtual void OnMoveUpCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.LineUp(); - } + _documentScrollInfo?.LineUp(); } /// @@ -1125,10 +1080,7 @@ protected virtual void OnMoveUpCommand() /// protected virtual void OnMoveDownCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.LineDown(); - } + _documentScrollInfo?.LineDown(); } /// @@ -1136,10 +1088,7 @@ protected virtual void OnMoveDownCommand() /// protected virtual void OnMoveLeftCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.LineLeft(); - } + _documentScrollInfo?.LineLeft(); } /// @@ -1147,10 +1096,7 @@ protected virtual void OnMoveLeftCommand() /// protected virtual void OnMoveRightCommand() { - if (_documentScrollInfo != null) - { - _documentScrollInfo.LineRight(); - } + _documentScrollInfo?.LineRight(); } /// @@ -2183,10 +2129,7 @@ private void OnFindInvoked(object sender, EventArgs e) //will be made visible after it's made. this.Focus(); - if (_documentScrollInfo != null) - { - _documentScrollInfo.MakeSelectionVisible(); - } + _documentScrollInfo?.MakeSelectionVisible(); //Put the focus back on the Find Toolbar's TextBox to search again. _findToolbar.GoToTextBox(); @@ -2232,10 +2175,7 @@ private void OnFindInvoked(object sender, EventArgs e) /// private void GoToFind() { - if (_findToolbar != null) - { - _findToolbar.GoToTextBox(); - } + _findToolbar?.GoToTextBox(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Expander.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Expander.cs index 3feb40d7cdb..8335466b4f8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Expander.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Expander.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -130,10 +130,7 @@ private static void OnIsExpandedChanged(DependencyObject d, DependencyPropertyCh // Fire accessibility event ExpanderAutomationPeer peer = UIElementAutomationPeer.FromElement(ep) as ExpanderAutomationPeer; - if(peer != null) - { - peer.RaiseExpandCollapseAutomationEvent(!newValue, newValue); - } + peer?.RaiseExpandCollapseAutomationEvent(!newValue, newValue); if (newValue) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs index f3c5616696d..8fb6b18b3d9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -689,10 +689,7 @@ protected virtual void OnFindCommand() /// protected virtual void OnPrintCommand() { - if (CurrentViewer != null) - { - CurrentViewer.Print(); - } + CurrentViewer?.Print(); } /// @@ -700,10 +697,7 @@ protected virtual void OnPrintCommand() /// protected virtual void OnCancelPrintCommand() { - if (CurrentViewer != null) - { - CurrentViewer.CancelPrint(); - } + CurrentViewer?.CancelPrint(); } /// @@ -1041,10 +1035,7 @@ private void DocumentChanged(FlowDocument oldDocument, FlowDocument newDocument) } // Attach document to the current viewer. - if (CurrentViewer != null) - { - CurrentViewer.SetDocument(newDocument); - } + CurrentViewer?.SetDocument(newDocument); // Document invalidation invalidates following properties: // - PageCount @@ -1065,10 +1056,7 @@ private void DocumentChanged(FlowDocument oldDocument, FlowDocument newDocument) // Document is also represented as Automation child. Need to invalidate peer to force update. FlowDocumentReaderAutomationPeer peer = UIElementAutomationPeer.FromElement(this) as FlowDocumentReaderAutomationPeer; - if (peer != null) - { - peer.InvalidatePeer(); - } + peer?.InvalidatePeer(); } /// @@ -1517,10 +1505,7 @@ private void TrySwitchViewingMode(object parameter) /// private void OnPreviousPageCommand() { - if (CurrentViewer != null) - { - CurrentViewer.PreviousPage(); - } + CurrentViewer?.PreviousPage(); } /// @@ -1528,10 +1513,7 @@ private void OnPreviousPageCommand() /// private void OnNextPageCommand() { - if (CurrentViewer != null) - { - CurrentViewer.NextPage(); - } + CurrentViewer?.NextPage(); } /// @@ -1539,10 +1521,7 @@ private void OnNextPageCommand() /// private void OnFirstPageCommand() { - if (CurrentViewer != null) - { - CurrentViewer.FirstPage(); - } + CurrentViewer?.FirstPage(); } /// @@ -1550,10 +1529,7 @@ private void OnFirstPageCommand() /// private void OnLastPageCommand() { - if (CurrentViewer != null) - { - CurrentViewer.LastPage(); - } + CurrentViewer?.LastPage(); } /// @@ -1584,10 +1560,7 @@ private void OnFindInvoked(object sender, EventArgs e) if ((findResult != null) && (!findResult.IsEmpty)) { // Bring find result into view. - if (CurrentViewer != null) - { - CurrentViewer.ShowFindResult(findResult); - } + CurrentViewer?.ShowFindResult(findResult); } else { @@ -1645,10 +1618,7 @@ private static void ViewingModeChanged(DependencyObject d, DependencyPropertyCha // Fire automation events if automation is active. FlowDocumentReaderAutomationPeer peer = UIElementAutomationPeer.FromElement(viewer) as FlowDocumentReaderAutomationPeer; - if (peer != null) - { - peer.RaiseCurrentViewChangedEvent((FlowDocumentReaderViewingMode)e.NewValue, (FlowDocumentReaderViewingMode)e.OldValue); - } + peer?.RaiseCurrentViewChangedEvent((FlowDocumentReaderViewingMode)e.NewValue, (FlowDocumentReaderViewingMode)e.OldValue); } /// @@ -1686,10 +1656,7 @@ private static void ViewingModeEnabledChanged(DependencyObject d, DependencyProp // Fire automation events if automation is active. FlowDocumentReaderAutomationPeer peer = UIElementAutomationPeer.FromElement(viewer) as FlowDocumentReaderAutomationPeer; - if (peer != null) - { - peer.RaiseSupportedViewsChangedEvent(e); - } + peer?.RaiseSupportedViewsChangedEvent(e); } /// @@ -1836,10 +1803,7 @@ private static void UpdateCaretElement(DependencyObject d, DependencyPropertyCha if (reader.Selection != null) { CaretElement caretElement = reader.Selection.CaretElement; - if (caretElement != null) - { - caretElement.InvalidateVisual(); - } + caretElement?.InvalidateVisual(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs index c5d1202c56f..ab238f4e9bc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -549,10 +549,7 @@ protected virtual void OnPrintCommand() if (docWriter != null && ia != null) { // Suspend layout on FlowDocumentView. - if (RenderScope != null) - { - RenderScope.SuspendLayout(); - } + RenderScope?.SuspendLayout(); // Store the current state of the document in the PrintingState paginator = ((IDocumentPaginatorSource)Document).DocumentPaginator as FlowDocumentPaginator; @@ -613,10 +610,7 @@ protected virtual void OnPrintCommand() protected virtual void OnCancelPrintCommand() { #if !DONOTREFPRINTINGASMMETA - if (_printingState != null) - { - _printingState.XpsDocumentWriter.CancelAsync(); - } + _printingState?.XpsDocumentWriter.CancelAsync(); #endif // DONOTREFPRINTINGASMMETA } @@ -1051,10 +1045,7 @@ private void ClearPrintingState() if (_printingState != null) { // Resume layout on FlowDocumentView. - if (RenderScope != null) - { - RenderScope.ResumeLayout(); - } + RenderScope?.ResumeLayout(); // Enable TextSelection, if it was previously enabled. if (_printingState.IsSelectionEnabled) @@ -1107,10 +1098,7 @@ private void HandleRequestBringIntoView(RequestBringIntoViewEventArgs args) // This supports navigating from baseURI#anchor to just baseURI. if (args.TargetObject == document) { - if (_contentHost != null) - { - _contentHost.ScrollToHome(); - } + _contentHost?.ScrollToHome(); args.Handled = true; // Mark the event as handled. } else if (args.TargetObject is UIElement) @@ -1265,10 +1253,7 @@ private void DocumentChanged(FlowDocument oldDocument, FlowDocument newDocument) // Document is also represented as Automation child. Need to invalidate peer to force update. FlowDocumentScrollViewerAutomationPeer peer = UIElementAutomationPeer.FromElement(this) as FlowDocumentScrollViewerAutomationPeer; - if (peer != null) - { - peer.InvalidatePeer(); - } + peer?.InvalidatePeer(); } /// @@ -1466,59 +1451,35 @@ private static void ExecutedRoutedEventHandler(object target, ExecutedRoutedEven } else if (args.Command == _commandLineDown) { - if (viewer._contentHost != null) - { - viewer._contentHost.LineDown(); - } + viewer._contentHost?.LineDown(); } else if (args.Command == _commandLineUp) { - if (viewer._contentHost != null) - { - viewer._contentHost.LineUp(); - } + viewer._contentHost?.LineUp(); } else if (args.Command == _commandLineLeft) { - if (viewer._contentHost != null) - { - viewer._contentHost.LineLeft(); - } + viewer._contentHost?.LineLeft(); } else if (args.Command == _commandLineRight) { - if (viewer._contentHost != null) - { - viewer._contentHost.LineRight(); - } + viewer._contentHost?.LineRight(); } else if (args.Command == NavigationCommands.NextPage) { - if (viewer._contentHost != null) - { - viewer._contentHost.PageDown(); - } + viewer._contentHost?.PageDown(); } else if (args.Command == NavigationCommands.PreviousPage) { - if (viewer._contentHost != null) - { - viewer._contentHost.PageUp(); - } + viewer._contentHost?.PageUp(); } else if (args.Command == NavigationCommands.FirstPage) { - if (viewer._contentHost != null) - { - viewer._contentHost.ScrollToHome(); - } + viewer._contentHost?.ScrollToHome(); } else if (args.Command == NavigationCommands.LastPage) { - if (viewer._contentHost != null) - { - viewer._contentHost.ScrollToEnd(); - } + viewer._contentHost?.ScrollToEnd(); } else { @@ -1765,10 +1726,7 @@ private static void UpdateCaretElement(DependencyObject d, DependencyPropertyCha if (viewer.Selection != null) { CaretElement caretElement = viewer.Selection.CaretElement; - if (caretElement != null) - { - caretElement.InvalidateVisual(); - } + caretElement?.InvalidateVisual(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Frame.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Frame.cs index 6ec3217cb97..5de1d14eadc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Frame.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Frame.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -208,8 +208,7 @@ protected virtual void OnContentRendered(EventArgs args) if (doContent != null) { IInputElement focusedElement = FocusManager.GetFocusedElement(doContent) as IInputElement; - if (focusedElement != null) - focusedElement.Focus(); + focusedElement?.Focus(); } if (ContentRendered != null) @@ -596,12 +595,9 @@ private void PostContentRendered() { // Post the firing of ContentRendered as Input priority work item so // that ContentRendered will be fired after render query empties. - if (_contentRenderedCallback != null) - { - // Content was changed again before the previous rendering completed (or at least - // before the Dispatcher got to Input priority callbacks). - _contentRenderedCallback.Abort(); - } + // Content was changed again before the previous rendering completed (or at least + // before the Dispatcher got to Input priority callbacks). + _contentRenderedCallback?.Abort(); _contentRenderedCallback = Dispatcher.BeginInvoke(DispatcherPriority.Input, (DispatcherOperationCallback) delegate (object arg) { @@ -981,7 +977,7 @@ public IEnumerable BackStack { get { - IEnumerable backStack = _ownJournalScope == null ? null : _ownJournalScope.BackStack; + IEnumerable backStack = _ownJournalScope?.BackStack; Debug.Assert(backStack == GetValue(BackStackProperty)); return backStack; } @@ -993,7 +989,7 @@ public IEnumerable ForwardStack { get { - IEnumerable fwdStack = _ownJournalScope == null ? null : _ownJournalScope.ForwardStack; + IEnumerable fwdStack = _ownJournalScope?.ForwardStack; Debug.Assert(fwdStack == GetValue(ForwardStackProperty)); return fwdStack; } @@ -1203,10 +1199,7 @@ internal override void PrepareForSerialization() Debug.Assert(JournalEntry.GetType().IsSerializable); } } - if (Journal != null) - { - Journal.PruneKeepAliveEntries(); - } + Journal?.PruneKeepAliveEntries(); } }; #pragma warning restore SYSLIB0050 @@ -1256,10 +1249,7 @@ void IJournalState.RestoreJournalState(CustomJournalStateInternal cjs) _ownJournalScope.Journal = state.Journal; } - if(state.JournalEntry != null) - { - state.JournalEntry.Navigate(this, NavigationMode.Back); - } + state.JournalEntry?.Navigate(this, NavigationMode.Back); } #endregion IJournalState @@ -1274,13 +1264,10 @@ internal override void OnPreApplyTemplate() { base.OnPreApplyTemplate(); - if (_ownJournalScope != null) - { - // This causes the Journal instance to be created. BackStackProperty and ForwardStackProperty - // should be set before the navigation chrome data-binds to them but after any Journal is - // restored from FramePersistState. - _ownJournalScope.EnsureJournal(); - } + // This causes the Journal instance to be created. BackStackProperty and ForwardStackProperty + // should be set before the navigation chrome data-binds to them but after any Journal is + // restored from FramePersistState. + _ownJournalScope?.EnsureJournal(); } // Invalidate resources on the frame content if the content isn't @@ -1331,10 +1318,7 @@ private void SwitchToOwnJournal() { // Entries created for this frame in the parent's journal have to be removed. JournalNavigationScope parentJns = GetParentJournal(false/*don't create*/); - if (parentJns != null) - { - parentJns.Journal.RemoveEntries(_navigationService.GuidId); - } + parentJns?.Journal.RemoveEntries(_navigationService.GuidId); _ownJournalScope = new JournalNavigationScope(this); _navigationService.InvalidateJournalNavigationScope(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs index a5bea90178f..f271b299074 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -663,10 +663,7 @@ protected override Size ArrangeOverride(Size arrangeSize) for (int i = 0, count = children.Count; i < count; ++i) { UIElement child = children[i]; - if (child != null) - { - child.Arrange(new Rect(arrangeSize)); - } + child?.Arrange(new Rect(arrangeSize)); } } else @@ -708,10 +705,7 @@ protected override Size ArrangeOverride(Size arrangeSize) // update render bound on grid lines renderer visual GridLinesRenderer gridLinesRenderer = EnsureGridLinesRenderer(); - if (gridLinesRenderer != null) - { - gridLinesRenderer.UpdateRenderBounds(arrangeSize); - } + gridLinesRenderer?.UpdateRenderBounds(arrangeSize); } } finally @@ -3875,8 +3869,8 @@ internal GridChildrenCollectionEnumeratorSimple(Grid grid, bool includeChildren) { Debug.Assert(grid != null); _currentEnumerator = -1; - _enumerator0 = new ColumnDefinitionCollection.Enumerator(grid.ExtData != null ? grid.ExtData.ColumnDefinitions : null); - _enumerator1 = new RowDefinitionCollection.Enumerator(grid.ExtData != null ? grid.ExtData.RowDefinitions : null); + _enumerator0 = new ColumnDefinitionCollection.Enumerator(grid.ExtData?.ColumnDefinitions); + _enumerator1 = new RowDefinitionCollection.Enumerator(grid.ExtData?.RowDefinitions); // GridLineRenderer is NOT included into this enumerator. _enumerator2Index = 0; if (includeChildren) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumnHeader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumnHeader.cs index ebbc6e017bd..a98c4c9d796 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumnHeader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumnHeader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -383,10 +383,7 @@ internal void CheckWidthForPreviousHeaderGripper() hideGripperRightHalf = DoubleUtil.LessThan(ActualWidth, _headerGripper.Width); } - if (_previousHeader != null) - { - _previousHeader.HideGripperRightHalf(hideGripperRightHalf); - } + _previousHeader?.HideGripperRightHalf(hideGripperRightHalf); UpdateGripperCursor(); } @@ -571,10 +568,7 @@ private static void PropertyChanged(DependencyObject d, DependencyPropertyChange header.SetFlag(flag, false); GridViewHeaderRowPresenter headerRowPresenter = header.Parent as GridViewHeaderRowPresenter; - if (headerRowPresenter != null) - { - headerRowPresenter.UpdateHeaderProperty(header, e.Property); - } + headerRowPresenter?.UpdateHeaderProperty(header, e.Property); } } } @@ -653,10 +647,7 @@ private void OnColumnHeaderGripperDragStarted(object sender, DragStartedEventArg private void MakeParentGotFocus() { GridViewHeaderRowPresenter headerRP = this.Parent as GridViewHeaderRowPresenter; - if (headerRP != null) - { - headerRP.MakeParentItemsControlGotFocus(); - } + headerRP?.MakeParentItemsControlGotFocus(); } // Resize the header @@ -809,8 +800,7 @@ private void ClickImplement() if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { AutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(this); - if (peer != null) - peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); + peer?.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } base.OnClick(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewHeaderRowPresenter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewHeaderRowPresenter.cs index 559d22fda9d..80a5d18ae37 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewHeaderRowPresenter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewHeaderRowPresenter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -942,10 +942,7 @@ private GridViewColumnHeader CreateAndInsertHeader(GridViewColumn column, int in { // case 2 GridViewColumnHeader parentAsGVCH = parent as GridViewColumnHeader; - if (parentAsGVCH != null) - { - parentAsGVCH.ClearValue(ContentControl.ContentProperty); - } + parentAsGVCH?.ClearValue(ContentControl.ContentProperty); } } } @@ -1519,10 +1516,7 @@ private void StartHeaderDrag() _draggingSrcHeader.SuppressClickEvent = true; // lock Columns during header dragging - if (Columns != null) - { - Columns.BlockWrite(); - } + Columns?.BlockWrite(); // Remove the old floating header, // then create & add the new one per the source header's type @@ -1548,10 +1542,7 @@ private void FinishHeaderDrag(bool isCancel) _indicator.Visibility = Visibility.Hidden; // unlock Columns during header dragging - if (Columns != null) - { - Columns.UnblockWrite(); - } + Columns?.UnblockWrite(); // if cancelled, do nothing if (!isCancel) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewRowPresenter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewRowPresenter.cs index d776aa0be8e..5c51b9785bd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewRowPresenter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewRowPresenter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -86,8 +86,8 @@ private static void OnContentChanged(DependencyObject d, DependencyPropertyChang // keeping the existing ContentPresenters // - Type oldType = (e.OldValue != null) ? e.OldValue.GetType() : null; - Type newType = (e.NewValue != null) ? e.NewValue.GetType() : null; + Type oldType = e.OldValue?.GetType(); + Type newType = e.NewValue?.GetType(); // DisconnectedItem doesn't count as a real type change if (e.NewValue == BindingExpressionBase.DisconnectedItem) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GroupItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GroupItem.cs index 8885c4bde56..db033990b02 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GroupItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GroupItem.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -247,10 +247,7 @@ internal void ClearItemContainer(object item, ItemsControl parentItemsControl) // the ItemValueStorage DP for this container. VirtualizingPanel vp = _itemsHost as VirtualizingPanel; - if (vp != null) - { - vp.OnClearChildrenInternal(); - } + vp?.OnClearChildrenInternal(); Generator.RemoveAllInternal(true /*saveRecycleQueue*/); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkPresenter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkPresenter.cs index 61a61dee8af..69ccc28002d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkPresenter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkPresenter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -208,10 +208,7 @@ protected override Size ArrangeOverride(Size arrangeSize) // We arrange our child as what Decorator does // exceopt we are using the available size computed from our cached measure size. UIElement child = Child; - if ( child != null ) - { - child.Arrange(new Rect(availableSize)); - } + child?.Arrange(new Rect(availableSize)); return arrangeSize; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs index 6e35c9d9b4b..418dfc4df20 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -247,10 +247,7 @@ public void Clear() throw new InvalidOperationException(SR.ItemsSourceInUse); } - if (_internalView != null) - { - _internalView.Clear(); - } + _internalView?.Clear(); ModelParent.ClearValue(ItemsControl.HasItemsPropertyKey); } @@ -1285,7 +1282,7 @@ public bool? IsLiveSorting get { ICollectionViewLiveShaping cvls = _collectionView as ICollectionViewLiveShaping; - return (cvls != null) ? cvls.IsLiveSorting : null; + return cvls?.IsLiveSorting; } set { @@ -1307,7 +1304,7 @@ public bool? IsLiveFiltering get { ICollectionViewLiveShaping cvls = _collectionView as ICollectionViewLiveShaping; - return (cvls != null) ? cvls.IsLiveFiltering : null; + return cvls?.IsLiveFiltering; } set { @@ -1329,7 +1326,7 @@ public bool? IsLiveGrouping get { ICollectionViewLiveShaping cvls = _collectionView as ICollectionViewLiveShaping; - return (cvls != null) ? cvls.IsLiveGrouping : null; + return cvls?.IsLiveGrouping; } set { @@ -1582,10 +1579,7 @@ internal IEnumerator LogicalChildren internal override void GetCollectionChangedSources(int level, Action> format, List sources) { format(level, this, false, sources); - if (_collectionView != null) - { - _collectionView.GetCollectionChangedSources(level+1, format, sources); - } + _collectionView?.GetCollectionChangedSources(level+1, format, sources); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemContainerGenerator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemContainerGenerator.cs index 2d694e0e512..fec1456ebb4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemContainerGenerator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemContainerGenerator.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1161,10 +1161,7 @@ internal void ChangeAlternationCount() for (int offset = 0; offset < block.ContainerCount; ++offset) { GroupItem gi = ((RealizedItemBlock)block).ContainerAt(offset) as GroupItem; - if (gi != null) - { - gi.Generator.ChangeAlternationCount(); - } + gi?.Generator.ChangeAlternationCount(); } block = block.Next; @@ -1954,7 +1951,7 @@ void PrepareGrouping() else { CollectionView cv = Host.View.CollectionView; - items = (cv == null) ? null : cv.Groups; + items = cv?.Groups; if (items == null) { items = Host.View; @@ -2064,8 +2061,7 @@ void OnSubgroupBecameNonEmpty(EmptyGroupItem groupItem, CollectionViewGroup grou { // Discard placeholder container. UnlinkContainerFromItem(groupItem, group); - if (_emptyGroupItems != null) - _emptyGroupItems.Remove(groupItem); + _emptyGroupItems?.Remove(groupItem); // inform layout as if the group just got added if (ItemsChanged != null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemsControl.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemsControl.cs index 09343d1aa16..9db8b53d3e6 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemsControl.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemsControl.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -481,10 +481,7 @@ protected virtual void OnItemTemplateChanged(DataTemplate oldItemTemplate, DataT { CheckTemplateSource(); - if (_itemContainerGenerator != null) - { - _itemContainerGenerator.Refresh(); - } + _itemContainerGenerator?.Refresh(); } @@ -709,10 +706,7 @@ protected virtual void OnItemContainerStyleChanged(Style oldItemContainerStyle, { Helper.CheckStyleAndStyleSelector("ItemContainer", ItemContainerStyleProperty, ItemContainerStyleSelectorProperty, this); - if (_itemContainerGenerator != null) - { - _itemContainerGenerator.Refresh(); - } + _itemContainerGenerator?.Refresh(); } @@ -957,10 +951,7 @@ public bool ShouldSerializeGroupStyle() private void OnGroupStyleChanged(object sender, NotifyCollectionChangedEventArgs e) { - if (_itemContainerGenerator != null) - { - _itemContainerGenerator.Refresh(); - } + _itemContainerGenerator?.Refresh(); } @@ -1003,10 +994,7 @@ private static void OnGroupStyleSelectorChanged(DependencyObject d, DependencyPr /// The new value of the GroupStyleSelector property. protected virtual void OnGroupStyleSelectorChanged(GroupStyleSelector oldGroupStyleSelector, GroupStyleSelector newGroupStyleSelector) { - if (_itemContainerGenerator != null) - { - _itemContainerGenerator.Refresh(); - } + _itemContainerGenerator?.Refresh(); } /// @@ -1392,10 +1380,7 @@ void IGeneratorHost.PrepareItemContainer(DependencyObject container, object item } TreeViewItem treeViewItem = container as TreeViewItem; - if (treeViewItem != null) - { - treeViewItem.PrepareItemContainer(item, this); - } + treeViewItem?.PrepareItemContainer(item, this); } /// @@ -1417,10 +1402,7 @@ void IGeneratorHost.ClearContainerForItem(DependencyObject container, object ite ClearContainerForItemOverride(container, item); TreeViewItem treeViewItem = container as TreeViewItem; - if (treeViewItem != null) - { - treeViewItem.ClearItemContainer(item, this); - } + treeViewItem?.ClearItemContainer(item, this); } else { @@ -1516,10 +1498,7 @@ public override void BeginInit() { base.BeginInit(); - if (_items != null) - { - _items.BeginInit(); - } + _items?.BeginInit(); } /// @@ -1529,10 +1508,7 @@ public override void EndInit() { if (IsInitPending) { - if (_items != null) - { - _items.EndInit(); - } + _items?.EndInit(); base.EndInit(); } @@ -1698,10 +1674,7 @@ protected override void OnKeyDown(KeyEventArgs e) { TextSearch instance = TextSearch.EnsureInstance(this); - if (instance != null) - { - instance.DeleteLastCharacter(); - } + instance?.DeleteLastCharacter(); } } } @@ -1835,10 +1808,7 @@ internal object OnBringItemIntoView(ItemInfo info) } VirtualizingPanel itemsHost = ItemsHost as VirtualizingPanel; - if (itemsHost != null) - { - itemsHost.BringIndexIntoView(info.Index); - } + itemsHost?.BringIndexIntoView(info.Index); } return null; @@ -1896,7 +1866,7 @@ internal void PrepareNavigateByLine(ItemInfo startingInfo, MakeVisible(startingInfo, direction, out startingElement); } - object startingItem = (startingInfo != null) ? startingInfo.Item : null; + object startingItem = startingInfo?.Item; // When we get here if startingItem is non-null, it must be on the visible page. NavigateByLineInternal(startingItem, @@ -1935,7 +1905,7 @@ internal bool NavigateByLine(ItemInfo startingInfo, MakeVisible(startingInfo, direction, out startingElement); } - object startingItem = (startingInfo != null) ? startingInfo.Item : null; + object startingItem = startingInfo?.Item; // When we get here if startingItem is non-null, it must be on the visible page. FrameworkElement container; @@ -2197,7 +2167,7 @@ internal void PrepareToNavigateByPage(ItemInfo startingInfo, MakeVisible(startingInfo, direction, out startingElement); } - object startingItem = (startingInfo != null) ? startingInfo.Item : null; + object startingItem = startingInfo?.Item; // When we get here if startingItem is non-null, it must be on the visible page. NavigateByPageInternal(startingItem, @@ -2243,7 +2213,7 @@ internal bool NavigateByPage( MakeVisible(startingInfo, direction, out startingElement); } - object startingItem = (startingInfo != null) ? startingInfo.Item : null; + object startingItem = startingInfo?.Item; // When we get here if startingItem is non-null, it must be on the visible page. FrameworkElement container; @@ -3808,10 +3778,7 @@ internal ItemInfo LeaseItemInfo(ItemInfo info, bool ensureIndex=false) // refresh an ItemInfo internal void RefreshItemInfo(ItemInfo info) { - if (info != null) - { - info.Refresh(ItemContainerGenerator); - } + info?.Refresh(ItemContainerGenerator); } [DebuggerDisplay("Index: {Index} Item: {Item}")] diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemsPresenter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemsPresenter.cs index cd80738cb75..3c8276cab66 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemsPresenter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemsPresenter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -220,7 +220,7 @@ void AttachToOwner() if (parentIP != null) owner = parentIP.Owner; - generator = (parentGI != null) ? parentGI.Generator : null; + generator = parentGI?.Generator; } _owner = owner; @@ -228,7 +228,7 @@ void AttachToOwner() // create the panel, based either on ItemsControl.ItemsPanel or GroupStyle.Panel ItemsPanelTemplate template = null; - GroupStyle groupStyle = (_generator != null) ? _generator.GroupStyle : null; + GroupStyle groupStyle = _generator?.GroupStyle; if (groupStyle != null) { // If GroupStyle.Panel is set then we dont honor ItemsControl.IsVirtualizing @@ -249,7 +249,7 @@ void AttachToOwner() else { // Its a leaf-level ItemsPresenter, therefore pick ItemsControl.ItemsPanel - template = (_owner != null) ? _owner.ItemsPanel : null; + template = _owner?.ItemsPanel; } Template = template; } @@ -285,10 +285,7 @@ private void OnPanelChanged(object sender, EventArgs e) // If our logical parent is a ScrollViewer then the visual parent is a ScrollContentPresenter. ScrollContentPresenter scp = VisualTreeHelper.GetParent(this) as ScrollContentPresenter; - if (scp != null) - { - scp.HookupScrollingComponents(); - } + scp?.HookupScrollingComponents(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Label.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Label.cs index 0a8c3419328..df77f837815 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Label.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Label.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -120,10 +120,7 @@ private static void OnTargetChanged(DependencyObject d, DependencyPropertyChange } } - if (newElement != null) - { - newElement.SetValue(LabeledByProperty, label); - } + newElement?.SetValue(LabeledByProperty, label); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBox.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBox.cs index 761c7b4089a..efe4b4646f7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBox.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBox.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -295,8 +295,7 @@ protected override void OnSelectionChanged(SelectionChangedEventArgs e) || AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection) ) { ListBoxAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(this) as ListBoxAutomationPeer; - if (peer != null) - peer.RaiseSelectionEvents(e); + peer?.RaiseSelectionEvents(e); } } @@ -884,10 +883,7 @@ private void MakeAnchorSelection(ListBoxItem actionItem, bool clearCurrent) } IDisposable d = enumerator as IDisposable; - if (d != null) - { - d.Dispose(); - } + d?.Dispose(); } finally { @@ -1027,7 +1023,7 @@ protected object AnchorItem internal ItemInfo AnchorItemInternal { get { return _anchorItem; } - set { _anchorItem = (value != null) ? value.Clone() : null; } // clone, so that adjustments to selection and anchor don't double-adjust + set { _anchorItem = value?.Clone(); } // clone, so that adjustments to selection and anchor don't double-adjust } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBoxItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBoxItem.cs index 1aee788f0d7..413f01cb7a1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBoxItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBoxItem.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -87,10 +87,7 @@ private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyCh bool isSelected = (bool) e.NewValue; Selector parentSelector = listItem.ParentSelector; - if (parentSelector != null) - { - parentSelector.RaiseIsSelectedChangedAutomationEvent(listItem, isSelected); - } + parentSelector?.RaiseIsSelectedChangedAutomationEvent(listItem, isSelected); if (isSelected) { @@ -273,10 +270,7 @@ private void HandleMouseButtonDown(MouseButton mouseButton) if (Selector.UiGetIsSelectable(this) && Focus()) { ListBox parent = ParentListBox; - if (parent != null) - { - parent.NotifyListItemClicked(this, mouseButton); - } + parent?.NotifyListItemClicked(this, mouseButton); } } @@ -347,10 +341,7 @@ protected internal override void OnVisualParentChanged(DependencyObject oldParen // If earlier, we decided to set focus to the old parent ListBox, do it here // after calling base so that the state for IsKeyboardFocusWithin is updated correctly. - if (oldItemsControl != null) - { - oldItemsControl.Focus(); - } + oldItemsControl?.Focus(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListView.cs index bf9451a047c..ef319671928 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -108,10 +108,7 @@ private static void OnViewChanged(DependencyObject d, DependencyPropertyChangedE ListViewAutomationPeer lvPeer = UIElementAutomationPeer.FromElement(listView) as ListViewAutomationPeer; if (lvPeer != null) { - if (lvPeer.ViewAutomationPeer != null) - { - lvPeer.ViewAutomationPeer.ViewDetached(); - } + lvPeer.ViewAutomationPeer?.ViewDetached(); if (newView != null) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MediaElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MediaElement.cs index c905c2d8371..bb208ba0e8a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MediaElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MediaElement.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -800,10 +800,7 @@ private static void VolumePropertyChanged(DependencyObject d, DependencyProperty MediaElement target = ((MediaElement) d); - if (target != null) - { - target._helper.SetVolume((double)e.NewValue); - } + target?._helper.SetVolume((double)e.NewValue); } private static void BalancePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -815,10 +812,7 @@ private static void BalancePropertyChanged(DependencyObject d, DependencyPropert MediaElement target = ((MediaElement) d); - if (target != null) - { - target._helper.SetBalance((double)e.NewValue); - } + target?._helper.SetBalance((double)e.NewValue); } private static void IsMutedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -830,10 +824,7 @@ private static void IsMutedPropertyChanged(DependencyObject d, DependencyPropert MediaElement target = ((MediaElement) d); - if (target != null) - { - target._helper.SetIsMuted((bool)e.NewValue); - } + target?._helper.SetIsMuted((bool)e.NewValue); } private static void ScrubbingEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -845,10 +836,7 @@ private static void ScrubbingEnabledPropertyChanged(DependencyObject d, Dependen MediaElement target = ((MediaElement) d); - if (target != null) - { - target._helper.SetScrubbingEnabled((bool)e.NewValue); - } + target?._helper.SetScrubbingEnabled((bool)e.NewValue); } private static @@ -865,10 +853,7 @@ DependencyPropertyChangedEventArgs e MediaElement target = (MediaElement)d; - if (target != null) - { - target._helper.SetUnloadedBehavior((MediaState)e.NewValue); - } + target?._helper.SetUnloadedBehavior((MediaState)e.NewValue); } private static @@ -885,10 +870,7 @@ DependencyPropertyChangedEventArgs e MediaElement target = (MediaElement)d; - if (target != null) - { - target._helper.SetLoadedBehavior((MediaState)e.NewValue); - } + target?._helper.SetLoadedBehavior((MediaState)e.NewValue); } internal diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs index 97cf59acf26..e77987c88d7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -957,10 +957,7 @@ private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyCha } MenuItemAutomationPeer peer = UIElementAutomationPeer.FromElement(menuItem) as MenuItemAutomationPeer; - if (peer != null) - { - peer.RaiseToggleStatePropertyChangedEvent(oldValue, newValue); - } + peer?.RaiseToggleStatePropertyChangedEvent(oldValue, newValue); } /// @@ -1383,8 +1380,7 @@ internal void OnClickImpl(bool userInitiated) if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { AutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(this); - if (peer != null) - peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); + peer?.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } // We have just caused all the popup windows to be hidden and queued for async @@ -1805,10 +1801,7 @@ private void MouseLeaveInMenuMode(MenuItemRole role) if (IsKeyboardFocusWithin) { ItemsControl parent = ItemsControl.ItemsControlFromItemContainer(this); - if (parent != null) - { - parent.Focus(); - } + parent?.Focus(); } } else @@ -2620,17 +2613,11 @@ private MenuItem CurrentSelection set { - if (_currentSelection != null) - { - _currentSelection.SetCurrentValueInternal(IsSelectedProperty, BooleanBoxes.FalseBox); - } + _currentSelection?.SetCurrentValueInternal(IsSelectedProperty, BooleanBoxes.FalseBox); _currentSelection = value; - if (_currentSelection != null) - { - _currentSelection.SetCurrentValueInternal(IsSelectedProperty, BooleanBoxes.TrueBox); - } + _currentSelection?.SetCurrentValueInternal(IsSelectedProperty, BooleanBoxes.TrueBox); // NOTE: (Win32 disparity) If CurrentSelection changes to null // and the focus was within the old CurrentSelection, we diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Page.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Page.cs index b246efbb1f0..2a2ed4fc679 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Page.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Page.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -614,10 +614,7 @@ protected override Size ArrangeOverride(Size arrangeBounds) { UIElement child = this.GetVisualChild(0) as UIElement; - if (child != null) - { - child.Arrange(new Rect(new Point(), arrangeBounds)); - } + child?.Arrange(new Rect(new Point(), arrangeBounds)); } return arrangeBounds; } @@ -658,7 +655,7 @@ protected internal sealed override void OnVisualParentChanged(DependencyObject o } // NOTE (Huwang 03/09/2007): The code below walks up the TemplatedParent chain until it finds the first Frame or Window. It does not - // check whether Window.Content or Frame.Content is Page. So it allows the scenario where Page can be in any element’s template and + // check whether Window.Content or Frame.Content is Page. So it allows the scenario where Page can be in any element’s template and // be parented by any element as long as the template is nested inside a Window or Frame, as demoed below // // diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PasswordBox.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PasswordBox.cs index 11b42ce5790..7afb5ac8ffe 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PasswordBox.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PasswordBox.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -898,10 +898,7 @@ private static void OnPasswordCharChanged(DependencyObject d, DependencyProperty PasswordBox passwordBox = (PasswordBox)d; // Force a layout refresh to display the new char. - if (passwordBox._renderScope != null) - { - passwordBox._renderScope.InvalidateMeasure(); - } + passwordBox._renderScope?.InvalidateMeasure(); } /// @@ -1054,10 +1051,7 @@ private void ResetSelection() { Select(0, 0); - if (this.ScrollViewer != null) - { - this.ScrollViewer.ScrollToHome(); - } + this.ScrollViewer?.ScrollToHome(); } /// @@ -1177,10 +1171,7 @@ private void AttachToVisualTree() /// private void DetachFromVisualTree() { - if (_textEditor != null) - { - _textEditor.Selection.DetachFromVisualTree(); - } + _textEditor?.Selection.DetachFromVisualTree(); // Invalidate our cached copy of scroll viewer. _scrollViewer = null; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs index 71705186aca..6b8ecbd8913 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -575,11 +575,8 @@ private void CloseToolTip(ToolTip tooltip) if (tooltip.IsOpen) { IInputElement element = owner as IInputElement; - if (element != null) - { - // ** Public callout - re-entrancy is possible **// - element.RaiseEvent(new ToolTipEventArgs(opening:false)); - } + // ** Public callout - re-entrancy is possible **// + element?.RaiseEvent(new ToolTipEventArgs(opening: false)); } } finally diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CalendarItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CalendarItem.cs index 3db9c371da1..ee8af2ccbba 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CalendarItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CalendarItem.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -873,10 +873,7 @@ private void Month_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) this._isMonthPressed = true; Mouse.Capture(this, CaptureMode.SubTree); - if (this.Owner != null) - { - this.Owner.OnCalendarButtonPressed(b, false); - } + this.Owner?.OnCalendarButtonPressed(b, false); } } @@ -931,18 +928,12 @@ private void HeaderButton_Click(object sender, RoutedEventArgs e) private void PreviousButton_Click(object sender, RoutedEventArgs e) { - if (this.Owner != null) - { - this.Owner.OnPreviousClick(); - } + this.Owner?.OnPreviousClick(); } private void NextButton_Click(object sender, RoutedEventArgs e) { - if (this.Owner != null) - { - this.Owner.OnNextClick(); - } + this.Owner?.OnNextClick(); } private void PopulateGrids() diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridCellsPresenter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridCellsPresenter.cs index 22d9b6291a4..aa58f3ff051 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridCellsPresenter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridCellsPresenter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -340,10 +340,7 @@ protected internal virtual void OnColumnsChanged(ObservableCollection Columns get { DataGridRow owningRow = DataGridRowOwner; - DataGrid owningDataGrid = (owningRow != null) ? owningRow.DataGridOwner : null; - return (owningDataGrid != null) ? owningDataGrid.Columns : null; + DataGrid owningDataGrid = owningRow?.DataGridOwner; + return owningDataGrid?.Columns; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeader.cs index 305342d0704..02415d495b6 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -192,10 +192,7 @@ private static void OnDisplayIndexChanged(DependencyObject d, DependencyProperty { header.SetLeftGripperVisibility(); DataGridColumnHeader nextColumnHeader = dataGrid.ColumnHeaderFromDisplayIndex(header.DisplayIndex + 1); - if (nextColumnHeader != null) - { - nextColumnHeader.SetLeftGripperVisibility(column.CanUserResize); - } + nextColumnHeader?.SetLeftGripperVisibility(column.CanUserResize); } } } @@ -295,10 +292,7 @@ private void OnColumnHeaderGripperDragStarted(object sender, DragStartedEventArg if (header.Column != null) { DataGrid dataGrid = header.Column.DataGridOwner; - if (dataGrid != null) - { - dataGrid.InternalColumns.OnColumnResizeStarted(); - } + dataGrid?.InternalColumns.OnColumnResizeStarted(); } e.Handled = true; @@ -346,10 +340,7 @@ private void OnColumnHeaderGripperDragCompleted(object sender, DragCompletedEven if (header.Column != null) { DataGrid dataGrid = header.Column.DataGridOwner; - if (dataGrid != null) - { - dataGrid.InternalColumns.OnColumnResizeCompleted(e.Canceled); - } + dataGrid?.InternalColumns.OnColumnResizeCompleted(e.Canceled); } e.Handled = true; @@ -548,10 +539,7 @@ private void SetNextHeaderLeftGripperVisibility(bool canUserResize) if (dataGrid.ColumnFromDisplayIndex(index).IsVisible) { DataGridColumnHeader nextHeader = dataGrid.ColumnHeaderFromDisplayIndex(index); - if (nextHeader != null) - { - nextHeader.SetLeftGripperVisibility(canUserResize); - } + nextHeader?.SetLeftGripperVisibility(canUserResize); break; } } @@ -758,10 +746,7 @@ protected override void OnClick() if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { AutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(this); - if (peer != null) - { - peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); - } + peer?.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } base.OnClick(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeadersPresenter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeadersPresenter.cs index b38d3c6087b..fe1c4af28ca 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeadersPresenter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeadersPresenter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -329,10 +329,7 @@ internal void NotifyPropertyChanged(DependencyObject d, string propertyName, Dep { if (e.Property == DataGridColumn.HeaderProperty) { - if (HeaderCollection != null) - { - HeaderCollection.NotifyHeaderPropertyChanged(column, e); - } + HeaderCollection?.NotifyHeaderPropertyChanged(column, e); } else { @@ -350,10 +347,7 @@ internal void NotifyPropertyChanged(DependencyObject d, string propertyName, Dep (e.Property == DataGrid.ColumnHeaderStyleProperty || e.Property == DataGrid.ColumnHeaderHeightProperty) ) { DataGridColumnHeader fillerColumnHeader = GetTemplateChild(ElementFillerColumnHeader) as DataGridColumnHeader; - if (fillerColumnHeader != null) - { - fillerColumnHeader.NotifyPropertyChanged(d, e); - } + fillerColumnHeader?.NotifyPropertyChanged(d, e); } } } @@ -820,10 +814,7 @@ private void FinishColumnHeaderDrag(bool isCancel) { _columnHeaderDragIndicator.Visibility = Visibility.Collapsed; DataGridColumnFloatingHeader floatingHeader = _columnHeaderDragIndicator as DataGridColumnFloatingHeader; - if (floatingHeader != null) - { - floatingHeader.ClearHeader(); - } + floatingHeader?.ClearHeader(); RemoveVisualChild(_columnHeaderDragIndicator); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridDetailsPresenter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridDetailsPresenter.cs index 2359d66a8e2..221bd2e252d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridDetailsPresenter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridDetailsPresenter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -47,7 +47,7 @@ private static object OnCoerceContentTemplate(DependencyObject d, object baseVal { var details = d as DataGridDetailsPresenter; var row = details.DataGridRowOwner; - var dataGrid = row != null ? row.DataGridOwner : null; + var dataGrid = row?.DataGridOwner; return DataGridHelper.GetCoercedTransferPropertyValue( details, baseValue, @@ -65,7 +65,7 @@ private static object OnCoerceContentTemplateSelector(DependencyObject d, object { var details = d as DataGridDetailsPresenter; var row = details.DataGridRowOwner; - var dataGrid = row != null ? row.DataGridOwner : null; + var dataGrid = row?.DataGridOwner; return DataGridHelper.GetCoercedTransferPropertyValue( details, baseValue, @@ -111,7 +111,7 @@ private void OnAnyMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs } DataGridRow rowOwner = DataGridRowOwner; - DataGrid dataGridOwner = rowOwner != null ? rowOwner.DataGridOwner : null; + DataGrid dataGridOwner = rowOwner?.DataGridOwner; if ((dataGridOwner != null) && (rowOwner != null)) { // HandleSelectionForRowHeaderAndDetailsInput below sets the CurrentCell @@ -158,7 +158,7 @@ internal FrameworkElement DetailsElement internal void SyncProperties() { DataGridRow owner = DataGridRowOwner; - Content = owner != null ? owner.Item : null; + Content = owner?.Item; DataGridHelper.TransferProperty(this, ContentTemplateProperty); DataGridHelper.TransferProperty(this, ContentTemplateSelectorProperty); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs index 8cc09ac9c6f..40f601f1be9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -333,7 +333,7 @@ private static object OnCoerceContentTemplate(DependencyObject d, object baseVal { var header = d as DataGridRowHeader; var row = header.ParentRow; - var dataGrid = row != null ? row.DataGridOwner : null; + var dataGrid = row?.DataGridOwner; return DataGridHelper.GetCoercedTransferPropertyValue( header, baseValue, @@ -351,7 +351,7 @@ private static object OnCoerceContentTemplateSelector(DependencyObject d, object { var header = d as DataGridRowHeader; var row = header.ParentRow; - var dataGrid = row != null ? row.DataGridOwner : null; + var dataGrid = row?.DataGridOwner; return DataGridHelper.GetCoercedTransferPropertyValue( header, baseValue, diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentPageView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentPageView.cs index d1a52a0d127..dee61a6ebcf 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentPageView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentPageView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -354,7 +354,7 @@ protected override sealed Size ArrangeOverride(Size finalSize) } Invariant.Assert(_pageHost != null); - pageVisual = (_documentPage == null) ? null : _documentPage.Visual; + pageVisual = _documentPage?.Visual; if (pageVisual == null) { // Remove existing visiual children. @@ -784,10 +784,7 @@ private object OnTransformChanged(object arg) private void OnPageConnected() { _newPageConnected = false; - if (_textView != null) - { - _textView.OnPageConnected(); - } + _textView?.OnPageConnected(); if (this.PageConnected != null && _documentPage != null) { this.PageConnected(this, EventArgs.Empty); @@ -799,10 +796,7 @@ private void OnPageConnected() /// private void OnPageDisconnected() { - if (_textView != null) - { - _textView.OnPageDisconnected(); - } + _textView?.OnPageDisconnected(); if (this.PageDisconnected != null) { this.PageDisconnected(this, EventArgs.Empty); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs index 92b1d0a1f8b..61ecc0cb3a3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -612,10 +612,7 @@ protected virtual void OnPrintCommand() protected virtual void OnCancelPrintCommand() { #if !DONOTREFPRINTINGASMMETA - if (_documentWriter != null) - { - _documentWriter.CancelAsync(); - } + _documentWriter?.CancelAsync(); #endif // DONOTREFPRINTINGASMMETA } @@ -629,7 +626,7 @@ protected virtual void OnDocumentChanged() // Document has been changed. Update existing DocumentPageViews to point them to the new Document. for (index = 0; index < _pageViews.Count; index++) { - _pageViews[index].DocumentPaginator = (_document != null) ? _document.DocumentPaginator : null; + _pageViews[index].DocumentPaginator = _document?.DocumentPaginator; } // Document invalidation invalidates following properties: @@ -848,15 +845,12 @@ private void UpdatePageViews() _pageViews = pageViews; for (index = 0; index < _pageViews.Count; index++) { - _pageViews[index].DocumentPaginator = (_document != null) ? _document.DocumentPaginator : null; + _pageViews[index].DocumentPaginator = _document?.DocumentPaginator; } // Collection of DocumentPageView has been changed. Need to update // TextView, if one already exists. - if (_textView != null) - { - _textView.OnPagesUpdated(); - } + _textView?.OnPagesUpdated(); // DocumentPageViews collection has been changed. Notify all listeners // and/or derived classes about this fact. @@ -1020,11 +1014,8 @@ private void AttachTextEditor() _textView = null; } - if (service != null) - { - // Must be enabled - otherwise it won't be on the tree - service.Disable(); - } + // Must be enabled - otherwise it won't be on the tree + service?.Disable(); // If new Document supports TextEditor, create one. // If the Document is already attached to TextEditor (TextSelection != null), @@ -1041,10 +1032,7 @@ private void AttachTextEditor() } // Re-enable the service in order to register on the new TextView - if (service != null) - { - service.Enable(service.Store); - } + service?.Enable(service.Store); } /// @@ -1330,10 +1318,7 @@ private void DocumentChanged(IDocumentPaginatorSource oldDocument, IDocumentPagi } DependencyObject depObj = oldDocument as DependencyObject; - if (depObj != null) - { - depObj.ClearValue(PathNode.HiddenParentProperty); - } + depObj?.ClearValue(PathNode.HiddenParentProperty); } // If DocumentViewer was created through style, then do not modify @@ -1413,10 +1398,7 @@ private void DocumentChanged(IDocumentPaginatorSource oldDocument, IDocumentPagi // Document is also represented as Automation child. Need to invalidate peer to force update. DocumentViewerBaseAutomationPeer peer = UIElementAutomationPeer.FromElement(this) as DocumentViewerBaseAutomationPeer; - if (peer != null) - { - peer.InvalidatePeer(); - } + peer?.InvalidatePeer(); // Respond to Document change - update state that is affected by this change. OnDocumentChanged(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs index df7fd9c875f..52979a11eba 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1181,10 +1181,7 @@ private void ReleasePopupCapture() { // restore capture to popup we took it from, if there was one Popup parentPopup = parentPopupRoot.Parent as Popup; - if (parentPopup != null) - { - parentPopup.EstablishPopupCapture(isRestoringCapture:true); - } + parentPopup?.EstablishPopupCapture(isRestoringCapture:true); } } _cacheValid[(int)CacheBits.CaptureEngaged] = false; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs index 54078514bb5..ad0c55ffce0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -91,10 +91,7 @@ private static void OnMinimumChanged(DependencyObject d, DependencyPropertyChang RangeBase ctrl = (RangeBase) d; RangeBaseAutomationPeer peer = UIElementAutomationPeer.FromElement(ctrl) as RangeBaseAutomationPeer; - if (peer != null) - { - peer.RaiseMinimumPropertyChangedEvent((double)e.OldValue, (double)e.NewValue); - } + peer?.RaiseMinimumPropertyChangedEvent((double)e.OldValue, (double)e.NewValue); ctrl.CoerceValue(MaximumProperty); ctrl.CoerceValue(ValueProperty); @@ -155,10 +152,7 @@ private static void OnMaximumChanged(DependencyObject d, DependencyPropertyChang RangeBase ctrl = (RangeBase) d; RangeBaseAutomationPeer peer = UIElementAutomationPeer.FromElement(ctrl) as RangeBaseAutomationPeer; - if (peer != null) - { - peer.RaiseMaximumPropertyChangedEvent((double)e.OldValue, (double)e.NewValue); - } + peer?.RaiseMaximumPropertyChangedEvent((double)e.OldValue, (double)e.NewValue); ctrl.CoerceValue(ValueProperty); ctrl.OnMaximumChanged((double) e.OldValue, (double) e.NewValue); @@ -228,10 +222,7 @@ private static void OnValueChanged(DependencyObject d, DependencyPropertyChanged RangeBase ctrl = (RangeBase)d; RangeBaseAutomationPeer peer = UIElementAutomationPeer.FromElement(ctrl) as RangeBaseAutomationPeer; - if (peer != null) - { - peer.RaiseValuePropertyChangedEvent((double)e.OldValue, (double)e.NewValue); - } + peer?.RaiseValuePropertyChangedEvent((double)e.OldValue, (double)e.NewValue); ctrl.OnValueChanged((double) e.OldValue, (double) e.NewValue); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RepeatButton.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RepeatButton.cs index 53e3d30adcc..5426581ced3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RepeatButton.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RepeatButton.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -124,10 +124,7 @@ private void StartTimer() /// private void StopTimer() { - if (_timer != null) - { - _timer.Stop(); - } + _timer?.Stop(); } /// @@ -199,8 +196,7 @@ protected override void OnClick() if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { AutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(this); - if (peer != null) - peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); + peer?.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } base.OnClick(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ResizeGrip.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ResizeGrip.cs index 6e63a884f32..c316cb635db 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ResizeGrip.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ResizeGrip.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -80,10 +80,7 @@ private void OnWindowServiceChanged(Window oldWindow, Window newWindow) oldWindow.ClearResizeGripControl(this); } - if (newWindow != null) - { - newWindow.SetResizeGripControl(this); - } + newWindow?.SetResizeGripControl(this); } #region DTypeThemeStyleKey diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Selector.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Selector.cs index 28b1e971527..bfbd8ab765d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Selector.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Selector.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -598,7 +598,7 @@ private object FindItemWithValue(object value, out int index) } } - Type selectedType = (value != null) ? value.GetType() : null; + Type selectedType = value?.GetType(); object selectedValue = value; DynamicValueConverter converter = new DynamicValueConverter(false); @@ -999,8 +999,7 @@ internal void RaiseIsSelectedChangedAutomationEvent(DependencyObject container, if (item != null) { SelectorItemAutomationPeer itemPeer = selectorPeer.ItemPeers[item] as SelectorItemAutomationPeer; - if (itemPeer != null) - itemPeer.RaiseAutomationIsSelectedChanged(isSelected); + itemPeer?.RaiseAutomationIsSelectedChanged(isSelected); } } } @@ -2420,8 +2419,7 @@ private void CreateDeltaSelectionChange(List unselectedItems, List @@ -1089,10 +1086,7 @@ protected override void OnKeyDown(KeyEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnKeyDown(e); - } + _textEditor?.OnKeyDown(e); } /// @@ -1107,10 +1101,7 @@ protected override void OnKeyUp(KeyEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnKeyUp(e); - } + _textEditor?.OnKeyUp(e); } /// @@ -1125,10 +1116,7 @@ protected override void OnTextInput(TextCompositionEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnTextInput(e); - } + _textEditor?.OnTextInput(e); } /// @@ -1143,10 +1131,7 @@ protected override void OnMouseDown(MouseButtonEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnMouseDown(e); - } + _textEditor?.OnMouseDown(e); } /// @@ -1161,10 +1146,7 @@ protected override void OnMouseMove(MouseEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnMouseMove(e); - } + _textEditor?.OnMouseMove(e); } /// @@ -1179,10 +1161,7 @@ protected override void OnMouseUp(MouseButtonEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnMouseUp(e); - } + _textEditor?.OnMouseUp(e); } /// @@ -1197,10 +1176,7 @@ protected override void OnQueryCursor(QueryCursorEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnQueryCursor(e); - } + _textEditor?.OnQueryCursor(e); } /// @@ -1215,10 +1191,7 @@ protected override void OnQueryContinueDrag(QueryContinueDragEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnQueryContinueDrag(e); - } + _textEditor?.OnQueryContinueDrag(e); } /// @@ -1233,10 +1206,7 @@ protected override void OnGiveFeedback(GiveFeedbackEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnGiveFeedback(e); - } + _textEditor?.OnGiveFeedback(e); } /// @@ -1251,10 +1221,7 @@ protected override void OnDragEnter(DragEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnDragEnter(e); - } + _textEditor?.OnDragEnter(e); } /// @@ -1269,10 +1236,7 @@ protected override void OnDragOver(DragEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnDragOver(e); - } + _textEditor?.OnDragOver(e); } /// @@ -1287,10 +1251,7 @@ protected override void OnDragLeave(DragEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnDragLeave(e); - } + _textEditor?.OnDragLeave(e); } /// @@ -1305,10 +1266,7 @@ protected override void OnDrop(DragEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnDrop(e); - } + _textEditor?.OnDrop(e); } /// @@ -1324,10 +1282,7 @@ protected override void OnContextMenuOpening(ContextMenuEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnContextMenuOpening(e); - } + _textEditor?.OnContextMenuOpening(e); } /// @@ -1342,10 +1297,7 @@ protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnGotKeyboardFocus(e); - } + _textEditor?.OnGotKeyboardFocus(e); } /// @@ -1360,10 +1312,7 @@ protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnLostKeyboardFocus(e); - } + _textEditor?.OnLostKeyboardFocus(e); } /// @@ -1379,10 +1328,7 @@ protected override void OnLostFocus(RoutedEventArgs e) return; } - if (_textEditor != null) - { - _textEditor.OnLostFocus(e); - } + _textEditor?.OnLostFocus(e); } // Allocates the initial render scope for this control. @@ -1529,10 +1475,7 @@ internal TextPointer GetTextPositionFromPointInternal(Point point, bool snapToTe // Transform to content coordinates. GeneralTransform transform = this.TransformToDescendant(this.RenderScope); - if (transform != null) - { - transform.TryTransform(point, out point); - } + transform?.TryTransform(point, out point); if (TextEditor.GetTextView(this.RenderScope).Validate(point)) { @@ -1582,10 +1525,7 @@ internal bool GetRectangleFromTextPosition(TextPointer position, out Rect rect) // Transform to RichTextBox control coordinates. offset = new Point(0, 0); GeneralTransform transform = this.TransformToDescendant(this.RenderScope); - if (transform != null) - { - transform.TryTransform(offset, out offset); - } + transform?.TryTransform(offset, out offset); rect.X -= offset.X; rect.Y -= offset.Y; } @@ -1641,19 +1581,13 @@ internal virtual void AttachToVisualTree() // Do the work of line up. Can be overridden by subclass to implement true line up. internal virtual void DoLineUp() { - if (this.ScrollViewer != null) - { - this.ScrollViewer.LineUp(); - } + this.ScrollViewer?.LineUp(); } // Do the work of line down. Can be overridden by subclass to implement true line down. internal virtual void DoLineDown() { - if (this.ScrollViewer != null) - { - this.ScrollViewer.LineDown(); - } + this.ScrollViewer?.LineDown(); } /// @@ -1852,10 +1786,7 @@ internal bool IsContentHostAvailable /// private void DetachFromVisualTree() { - if (_textEditor != null) - { - _textEditor.Selection.DetachFromVisualTree(); - } + _textEditor?.Selection.DetachFromVisualTree(); // Detach scroll handler from old scroll viewer. // Note that this.ScrollViewer will walk the tree from current TextEditor's render scope up to its ui scope. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToggleButton.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToggleButton.cs index f9b4d800931..c149487f7ee 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToggleButton.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToggleButton.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -163,10 +163,7 @@ private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyCha //doing soft casting here because the peer can be that of RadioButton and it is not derived from //ToggleButtonAutomationPeer - specifically to avoid implementing TogglePattern ToggleButtonAutomationPeer peer = UIElementAutomationPeer.FromElement(button) as ToggleButtonAutomationPeer; - if (peer != null) - { - peer.RaiseToggleStatePropertyChangedEvent(oldValue, newValue); - } + peer?.RaiseToggleStatePropertyChangedEvent(oldValue, newValue); if (newValue == true) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarOverflowPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarOverflowPanel.cs index 684bdb6944d..65bb377168d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarOverflowPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarOverflowPanel.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -218,7 +218,7 @@ private ToolBarPanel ToolBarPanel get { ToolBar tb = ToolBar; - return tb == null ? null : tb.ToolBarPanel; + return tb?.ToolBarPanel; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarPanel.cs index 798216911d1..a3d9c29b2c0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarPanel.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -265,10 +265,7 @@ protected override Size MeasureOverride(Size constraint) MaxLength = (horizontal ? stackDesiredSize.Width : stackDesiredSize.Height) + overflowExtent; ToolBar toolbar = ToolBar; - if (toolbar != null) - { - toolbar.SetValue(ToolBar.HasOverflowItemsPropertyKey, hasAlwaysOverflowItems || hasAsNeededOverflowItems); - } + toolbar?.SetValue(ToolBar.HasOverflowItemsPropertyKey, hasAlwaysOverflowItems || hasAsNeededOverflowItems); } else { @@ -416,10 +413,7 @@ private void AddChildren(GeneratorPosition pos, int itemCount) else { ItemContainerGenerator icg = Generator as ItemContainerGenerator; - if (icg != null) - { - icg.Verify(); - } + icg?.Verify(); } } } @@ -475,10 +469,7 @@ private void ReplaceChildren(GeneratorPosition pos, int itemCount, int container else { ItemContainerGenerator icg = Generator as ItemContainerGenerator; - if (icg != null) - { - icg.Verify(); - } + icg?.Verify(); } } } @@ -523,7 +514,7 @@ private ToolBarOverflowPanel ToolBarOverflowPanel get { ToolBar tb = ToolBar; - return tb == null ? null : tb.ToolBarOverflowPanel; + return tb?.ToolBarOverflowPanel; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Track.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Track.cs index 4a6d3a01e2b..283d37de9ed 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Track.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Track.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -507,22 +507,19 @@ protected override Size ArrangeOverride(Size arrangeSize) offset.Y = isDirectionReversed ? decreaseButtonLength + thumbLength : 0.0; pieceSize.Height = increaseButtonLength; - if (IncreaseRepeatButton != null) - IncreaseRepeatButton.Arrange(new Rect(offset, pieceSize)); + IncreaseRepeatButton?.Arrange(new Rect(offset, pieceSize)); offset.Y = isDirectionReversed ? 0.0 : increaseButtonLength + thumbLength; pieceSize.Height = decreaseButtonLength; - if (DecreaseRepeatButton != null) - DecreaseRepeatButton.Arrange(new Rect(offset, pieceSize)); + DecreaseRepeatButton?.Arrange(new Rect(offset, pieceSize)); offset.Y = isDirectionReversed ? decreaseButtonLength : increaseButtonLength; pieceSize.Height = thumbLength; - if (Thumb != null) - Thumb.Arrange(new Rect(offset, pieceSize)); + Thumb?.Arrange(new Rect(offset, pieceSize)); ThumbCenterOffset = offset.Y + (thumbLength * 0.5); } @@ -538,22 +535,19 @@ protected override Size ArrangeOverride(Size arrangeSize) offset.X = isDirectionReversed ? increaseButtonLength + thumbLength : 0.0; pieceSize.Width = decreaseButtonLength; - if (DecreaseRepeatButton != null) - DecreaseRepeatButton.Arrange(new Rect(offset, pieceSize)); + DecreaseRepeatButton?.Arrange(new Rect(offset, pieceSize)); offset.X = isDirectionReversed ? 0.0 : decreaseButtonLength + thumbLength; pieceSize.Width = increaseButtonLength; - if (IncreaseRepeatButton != null) - IncreaseRepeatButton.Arrange(new Rect(offset, pieceSize)); + IncreaseRepeatButton?.Arrange(new Rect(offset, pieceSize)); offset.X = isDirectionReversed ? increaseButtonLength : decreaseButtonLength; pieceSize.Width = thumbLength; - if (Thumb != null) - Thumb.Arrange(new Rect(offset, pieceSize)); + Thumb?.Arrange(new Rect(offset, pieceSize)); ThumbCenterOffset = offset.X + (thumbLength * 0.5); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ProgressBar.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ProgressBar.cs index 994cfa55330..bd281174187 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ProgressBar.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ProgressBar.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -101,10 +101,7 @@ private static void OnIsIndeterminateChanged(DependencyObject d, DependencyPrope // Invalidate automation peer ProgressBarAutomationPeer peer = UIElementAutomationPeer.FromElement(progressBar) as ProgressBarAutomationPeer; - if (peer != null) - { - peer.InvalidatePeer(); - } + peer?.InvalidatePeer(); progressBar.SetProgressBarGlowElementBrush(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RichTextBox.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RichTextBox.cs index a574e738b1c..04f6a0c653e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RichTextBox.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RichTextBox.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -798,10 +798,7 @@ private static void OnIsDocumentEnabledChanged(DependencyObject d, DependencyPro { RichTextBox richTextBox = (RichTextBox)d; - if (richTextBox.Document != null) - { - richTextBox.Document.CoerceValue(IsEnabledProperty); - } + richTextBox.Document?.CoerceValue(IsEnabledProperty); } #endregion Private Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ScrollViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ScrollViewer.cs index 46ae5bbb35f..ffcc26ebcb4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ScrollViewer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ScrollViewer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1454,10 +1454,7 @@ public static PanningMode GetPanningMode(DependencyObject element) private static void OnPanningModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ScrollViewer sv = d as ScrollViewer; - if (sv != null) - { - sv.OnPanningModeChanged(); - } + sv?.OnPanningModeChanged(); } /// @@ -2412,15 +2409,12 @@ private void OnLayoutUpdated(object sender, EventArgs e) // Fire automation events if automation is active. ScrollViewerAutomationPeer peer = UIElementAutomationPeer.FromElement(this) as ScrollViewerAutomationPeer; - if(peer != null) - { - peer.RaiseAutomationEvents(oldExtentWidth, + peer?.RaiseAutomationEvents(oldExtentWidth, oldExtentHeight, oldViewportWidth, oldViewportHeight, oldActualHorizontalOffset, oldActualVerticalOffset); - } } finally { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SinglePageViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SinglePageViewer.cs index 6b801d3b099..2a94d477177 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SinglePageViewer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SinglePageViewer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1457,10 +1457,7 @@ private static void UpdateCaretElement(DependencyObject d, DependencyPropertyCha if (viewer.Selection != null) { CaretElement caretElement = viewer.Selection.CaretElement; - if (caretElement != null) - { - caretElement.InvalidateVisual(); - } + caretElement?.InvalidateVisual(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs index 1aa5dccf1f3..762904790a5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -206,55 +206,37 @@ private bool IsInverted(Slider slider) private static void OnIncreaseSmallCommand(object sender, ExecutedRoutedEventArgs e) { Slider slider = sender as Slider; - if (slider != null) - { - slider.OnIncreaseSmall(); - } + slider?.OnIncreaseSmall(); } private static void OnDecreaseSmallCommand(object sender, ExecutedRoutedEventArgs e) { Slider slider = sender as Slider; - if (slider != null) - { - slider.OnDecreaseSmall(); - } + slider?.OnDecreaseSmall(); } private static void OnMaximizeValueCommand(object sender, ExecutedRoutedEventArgs e) { Slider slider = sender as Slider; - if (slider != null) - { - slider.OnMaximizeValue(); - } + slider?.OnMaximizeValue(); } private static void OnMinimizeValueCommand(object sender, ExecutedRoutedEventArgs e) { Slider slider = sender as Slider; - if (slider != null) - { - slider.OnMinimizeValue(); - } + slider?.OnMinimizeValue(); } private static void OnIncreaseLargeCommand(object sender, ExecutedRoutedEventArgs e) { Slider slider = sender as Slider; - if (slider != null) - { - slider.OnIncreaseLarge(); - } + slider?.OnIncreaseLarge(); } private static void OnDecreaseLargeCommand(object sender, ExecutedRoutedEventArgs e) { Slider slider = sender as Slider; - if (slider != null) - { - slider.OnDecreaseLarge(); - } + slider?.OnDecreaseLarge(); } #endregion Commands @@ -1351,7 +1333,7 @@ public override void OnApplyTemplate() if (_autoToolTip != null) { - _autoToolTip.PlacementTarget = Track != null ? Track.Thumb : null; + _autoToolTip.PlacementTarget = Track?.Thumb; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SoundPlayerAction.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SoundPlayerAction.cs index fd14f68f661..c0af3c54728 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SoundPlayerAction.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SoundPlayerAction.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -38,10 +38,7 @@ public SoundPlayerAction() /// public void Dispose() { - if (m_player != null) - { - m_player.Dispose(); - } + m_player?.Dispose(); } @@ -197,10 +194,7 @@ private Object OnLoadStreamCompleted(Object asyncResultArg) if (m_uriChangedWhileLoadingStream) // The source URI was changed, redo Stream loading { m_uriChangedWhileLoadingStream = false; - if (newStream != null) // Don't hold on to the new stream - it's not needed anymore - { - newStream.Dispose(); - } + newStream?.Dispose(); BeginLoadStream(); } else if (newStream != null) // We loaded the Stream, begin buffering it diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SpellCheck.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SpellCheck.cs index 68b1cce8afd..990b1c6762e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SpellCheck.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SpellCheck.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -215,10 +215,7 @@ private static void OnSpellingReformChanged(DependencyObject d, DependencyProper { TextEditor textEditor = TextEditor._GetTextEditor(textBoxBase); - if (textEditor != null) - { - textEditor.SetSpellingReform((SpellingReform)e.NewValue); - } + textEditor?.SetSpellingReform((SpellingReform)e.NewValue); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Stack.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Stack.cs index 6055505c7bd..d38151d9cad 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Stack.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Stack.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -798,7 +798,7 @@ private static void ResetScrolling(StackPanel element) // At the time this method is called, scrolling state is in its new, valid state. private void OnScrollChange() { - if (ScrollOwner != null) { ScrollOwner.InvalidateScrollInfo(); } + ScrollOwner?.InvalidateScrollInfo(); } private static void VerifyScrollingData(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size viewport, Size extent, Vector offset) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/StickyNote.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/StickyNote.cs index ca3ea271756..d50c1ddae2d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/StickyNote.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/StickyNote.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -178,18 +178,12 @@ public override void OnApplyTemplate() if (!this.IsExpanded) { Button button = GetIconButton(); - if (button != null) - { - button.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnButtonClick)); - } + button?.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnButtonClick)); } else { Button closeButton = GetCloseButton(); - if (closeButton != null) - { - closeButton.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnButtonClick)); - } + closeButton?.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnButtonClick)); Thumb titleThumb = GetTitleThumb(); if (titleThumb != null) @@ -794,8 +788,7 @@ private static void OnFontPropertyChanged(DependencyObject d, DependencyProperty if (stickyNoteControl.Content != null && stickyNoteControl.Content.Type != StickyNoteType.Ink) { FrameworkElement innerControl = stickyNoteControl.Content.InnerControl; - if (innerControl != null) - innerControl.SetValue(e.Property, e.NewValue); + innerControl?.SetValue(e.Property, e.NewValue); } } @@ -811,8 +804,7 @@ private static void _UpdateInkDrawingAttributes(DependencyObject d, DependencyPr if (e.Property == ForegroundProperty && stickyNoteControl.Content != null && stickyNoteControl.Content.Type != StickyNoteType.Ink) { FrameworkElement innerControl = stickyNoteControl.Content.InnerControl; - if (innerControl != null) - innerControl.SetValue(ForegroundProperty, e.NewValue); + innerControl?.SetValue(ForegroundProperty, e.NewValue); } } @@ -976,11 +968,8 @@ private void OnInkStrokesChanged(object sender, StrokeCollectionChangedEventArgs Invariant.Assert(Content != null && Content.InnerControl is InkCanvas); FrameworkElement parent = VisualTreeHelper.GetParent(Content.InnerControl) as FrameworkElement; - if (parent != null) - { - // Invalidate ContentArea's measure so that scrollbar could be updated correctly. - parent.InvalidateMeasure(); - } + // Invalidate ContentArea's measure so that scrollbar could be updated correctly. + parent?.InvalidateMeasure(); } //fire trace event @@ -1284,16 +1273,10 @@ private void ClearCachedControls() } Button closeButton = GetCloseButton(); - if (closeButton != null) - { - closeButton.RemoveHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnButtonClick)); - } + closeButton?.RemoveHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnButtonClick)); Button iconButton = GetIconButton(); - if (iconButton != null) - { - iconButton.RemoveHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnButtonClick)); - } + iconButton?.RemoveHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnButtonClick)); Thumb titleThumb = GetTitleThumb(); if (titleThumb != null) @@ -1395,10 +1378,7 @@ private void GiveUpFocus() private void BringToFront() { PresentationContext pc = ((IAnnotationComponent)this).PresentationContext; - if ( pc != null ) - { - pc.BringToFront(this); - } + pc?.BringToFront(this); } /// @@ -1409,10 +1389,7 @@ private void BringToFront() private void SendToBack() { PresentationContext pc = ((IAnnotationComponent)this).PresentationContext; - if (pc != null) - { - pc.SendToBack(this); - } + pc?.SendToBack(this); } /// @@ -1421,10 +1398,7 @@ private void SendToBack() private void InvalidateTransform() { PresentationContext pc = ((IAnnotationComponent)this).PresentationContext; - if ( pc != null ) - { - pc.InvalidateTransform(this); - } + pc?.InvalidateTransform(this); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TabControl.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TabControl.cs index 008a94040cb..1828b20621d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TabControl.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TabControl.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -80,8 +80,7 @@ private static void OnTabStripPlacementPropertyChanged(DependencyObject d, Depen for (int i = 0; i < tabItemCollection.Count; i++) { TabItem ti = tc.ItemContainerGenerator.ContainerFromIndex(i) as TabItem; - if (ti != null) - ti.CoerceValue(TabItem.TabStripPlacementProperty); + ti?.CoerceValue(TabItem.TabStripPlacementProperty); } } @@ -341,10 +340,7 @@ protected override void OnSelectionChanged(SelectionChangedEventArgs e) { // If keyboard focus is within the control, make sure it is going to the correct place TabItem item = GetSelectedTabItem(); - if (item != null) - { - item.SetFocus(); - } + item?.SetFocus(); } UpdateSelectedContent(); } @@ -359,10 +355,7 @@ protected override void OnSelectionChanged(SelectionChangedEventArgs e) { // If keyboard focus is within the control, make sure it is going to the correct place TabItem item = GetSelectedTabItem(); - if (item != null) - { - item.SetFocus(); - } + item?.SetFocus(); } base.OnSelectionChanged(e); } @@ -373,8 +366,7 @@ protected override void OnSelectionChanged(SelectionChangedEventArgs e) || AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection) ) { TabControlAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(this) as TabControlAutomationPeer; - if (peer != null) - peer.RaiseSelectionEvents(e); + peer?.RaiseSelectionEvents(e); } } @@ -392,8 +384,7 @@ protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e) if (startIndex > Items.Count) startIndex = 0; TabItem nextTabItem = FindNextTabItem(startIndex, -1); - if (nextTabItem != null) - nextTabItem.SetCurrentValueInternal(TabItem.IsSelectedProperty, MS.Internal.KnownBoxes.BooleanBoxes.TrueBox); + nextTabItem?.SetCurrentValueInternal(TabItem.IsSelectedProperty, MS.Internal.KnownBoxes.BooleanBoxes.TrueBox); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TabItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TabItem.cs index 048b3bb90a5..0aa8663bb3c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TabItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TabItem.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -92,10 +92,7 @@ private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyCh bool isSelected = (bool)e.NewValue; TabControl parentTabControl = tabItem.TabControlParent; - if (parentTabControl != null) - { - parentTabControl.RaiseIsSelectedChangedAutomationEvent(tabItem, isSelected); - } + parentTabControl?.RaiseIsSelectedChangedAutomationEvent(tabItem, isSelected); if (isSelected) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextAdaptor.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextAdaptor.cs index 2467d06280c..d10b058d5f7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextAdaptor.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextAdaptor.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -199,10 +199,7 @@ internal ITextView GetUpdatedTextView() internal void Select(ITextPointer start, ITextPointer end) { // Update the selection range - if (_textContainer.TextSelection != null) - { - _textContainer.TextSelection.Select(start, end); - } + _textContainer.TextSelection?.Select(start, end); } /// @@ -263,10 +260,7 @@ internal void ScrollIntoView(ITextPointer start, ITextPointer end, bool alignToT } FrameworkElement fe = renderScope as FrameworkElement; - if (fe != null) - { - fe.BringIntoView(rangeVisibleBounds); - } + fe?.BringIntoView(rangeVisibleBounds); } else { @@ -274,10 +268,7 @@ internal void ScrollIntoView(ITextPointer start, ITextPointer end, bool alignToT ITextPointer pointer = alignToTop ? start.CreatePointer() : end.CreatePointer(); pointer.MoveToElementEdge(alignToTop ? ElementEdge.AfterStart : ElementEdge.AfterEnd); FrameworkContentElement element = pointer.GetAdjacentElement(LogicalDirection.Backward) as FrameworkContentElement; - if (element != null) - { - element.BringIntoView(); - } + element?.BringIntoView(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs index 048f9060cc7..9c3e8ee3466 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1237,10 +1237,7 @@ protected sealed override Size MeasureOverride(Size constraint) ClearLineMetrics(); - if (_complexContent != null) - { - _complexContent.TextView.Invalidate(); - } + _complexContent?.TextView.Invalidate(); // To determine natural size of the text TextAlignment has to be ignored. // Since for rendering/hittesting lines are recreated, it can be done without @@ -1382,10 +1379,7 @@ protected sealed override Size ArrangeOverride(Size arrangeSize) MS.Internal.PtsHost.TextPanelDebug.StartTimer("TextBlock.ArrangeOverride", MS.Internal.PtsHost.TextPanelDebug.Category.MeasureArrange); #endif // Remove all existing visuals. If there are inline objects, they will be added below. - if (_complexContent != null) - { - _complexContent.VisualChildren.Clear(); - } + _complexContent?.VisualChildren.Clear(); ArrayList inlineObjects = InlineObjects; int lineCount = LineCount; @@ -1907,10 +1901,7 @@ protected override AutomationPeer OnCreateAutomationPeer() /// internal void RemoveChild(Visual child) { - if (_complexContent != null) - { - _complexContent.VisualChildren.Remove(child); - } + _complexContent?.VisualChildren.Remove(child); } /// @@ -2773,7 +2764,7 @@ internal bool IsTypographyDefaultValue //------------------------------------------------------------------- private ArrayList InlineObjects { - get { return (_complexContent == null) ? null : _complexContent.InlineObjects; } + get { return _complexContent?.InlineObjects; } set { if (_complexContent != null) _complexContent.InlineObjects = value; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextSearch.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextSearch.cs index dcda66c0e04..f16b11d71a7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextSearch.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextSearch.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -283,8 +283,8 @@ internal bool DeleteLastCharacter() /// /// Gets the length of the prefix (the prefix of matchedText matched by newText) and the rest of the string from the matchedText /// It takes care of compressions or expansions in both matchedText and newText which could be impacting the length of the string - /// For example: length of prefix would be 5 and the rest would be 2 if matchedText is "Grosses" and newText is ""Groß" - /// length of prefix would be 4 and the rest would be 2 if matchedText is ""Großes" and newText is "Gross" as "ß" = "ss" + /// For example: length of prefix would be 5 and the rest would be 2 if matchedText is "Grosses" and newText is ""Groß" + /// length of prefix would be 4 and the rest would be 2 if matchedText is ""Großes" and newText is "Gross" as "ß" = "ss" /// /// /// string that is assumed to contain prefix which matches newText /// string that is assumed to match a prefix of matchedText @@ -503,9 +503,9 @@ internal static MatchedTextInfo FindMatchingPrefix(ItemsControl itemsControl, st // There could be compressions or expansions in either matched text or inputted text which means // length of the prefix in the matched text and length of the inputted text could be different - // for example: "Grosses" would match for the input text "Groß" where the prefix length in matched text is 5 + // for example: "Grosses" would match for the input text "Groß" where the prefix length in matched text is 5 // whereas the length of the inputted text is 4. Same matching rule applies for the other way as well with - // "Groß" in matched text for the inputted text "Gross" + // "Groß" in matched text for the inputted text "Gross" if (matchedItemIndex >= 0) { int matchedPrefixLength; @@ -680,10 +680,7 @@ private void ResetState() _charsEntered.Clear(); } - if(_timeoutTimer != null) - { - _timeoutTimer.Stop(); - } + _timeoutTimer?.Stop(); _timeoutTimer = null; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolBar.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolBar.cs index c41ddcde6e5..6791b589208 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolBar.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolBar.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -383,10 +383,7 @@ private static void OnOverflowModeChanged(DependencyObject element, DependencyPr // invalidate layout so that the child can be placed in the correct // location (in the main bar or the overflow menu). ToolBar toolBar = ItemsControl.ItemsControlFromItemContainer(element) as ToolBar; - if (toolBar != null) - { - toolBar.InvalidateLayout(); - } + toolBar?.InvalidateLayout(); } private void InvalidateLayout() @@ -399,12 +396,9 @@ private void InvalidateLayout() InvalidateMeasure(); ToolBarPanel toolBarPanel = this.ToolBarPanel; - if (toolBarPanel != null) - { - // Whether elements are in the overflow or not is decided - // in ToolBarPanel.MeasureOverride. - toolBarPanel.InvalidateMeasure(); - } + // Whether elements are in the overflow or not is decided + // in ToolBarPanel.MeasureOverride. + toolBarPanel?.InvalidateMeasure(); } private static bool IsValidOverflowMode(object o) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolBarTray.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolBarTray.cs index 8a12641423c..8902f602ba4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolBarTray.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolBarTray.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -658,10 +658,7 @@ private Point TransformPointToToolBar(ToolBar toolBar, Point point) { Point p = point; GeneralTransform transform = this.TransformToDescendant(toolBar); - if (transform != null) - { - transform.TryTransform(point, out p); - } + transform?.TryTransform(point, out p); return p; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolTip.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolTip.cs index 4e9e92ebe98..f28b1723b0c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolTip.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolTip.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -167,8 +167,7 @@ private static void OnIsOpenChanged(DependencyObject d, DependencyPropertyChange if (AutomationPeer.ListenerExists(AutomationEvents.ToolTipClosed)) { AutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(t); - if (peer != null) - peer.RaiseAutomationEvent(AutomationEvents.ToolTipClosed); + peer?.RaiseAutomationEvent(AutomationEvents.ToolTipClosed); } } @@ -526,10 +525,7 @@ private void HookupParentPopup() internal void ForceClose() { - if (_parentPopup != null) - { - _parentPopup.ForceClose(); - } + _parentPopup?.ForceClose(); } private void OnPopupCouldClose(object sender, EventArgs e) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TreeView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TreeView.cs index 0ca1fa64b57..7ce19e993bb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TreeView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TreeView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -247,16 +247,14 @@ internal void ChangeSelection(object data, TreeViewItem container, bool selected && AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) ) { TreeViewItemAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(_selectedContainer) as TreeViewItemAutomationPeer; - if (peer != null) - peer.RaiseAutomationSelectionEvent(AutomationEvents.SelectionItemPatternOnElementSelected); + peer?.RaiseAutomationSelectionEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } if ( oldContainer != null && AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection) ) { TreeViewItemAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(oldContainer) as TreeViewItemAutomationPeer; - if (peer != null) - peer.RaiseAutomationSelectionEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); + peer?.RaiseAutomationSelectionEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } RoutedPropertyChangedEventArgs e = new RoutedPropertyChangedEventArgs(oldValue, newValue, SelectedItemChangedEvent); @@ -699,9 +697,7 @@ private bool HandleScrollByPage(KeyEventArgs e) { IInputElement originalFocusedElement = Keyboard.FocusedElement; ItemsControl parentItemsControl = ItemsControl.ItemsControlFromItemContainer(_selectedContainer); - ItemInfo startingInfo = (parentItemsControl != null) - ? parentItemsControl.ItemInfoFromContainer(_selectedContainer) - : null; + ItemInfo startingInfo = parentItemsControl?.ItemInfoFromContainer(_selectedContainer); FrameworkElement startingContainer = _selectedContainer.HeaderElement; if (startingContainer == null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TreeViewItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TreeViewItem.cs index 423acf149e5..3125005732a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TreeViewItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TreeViewItem.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -110,10 +110,7 @@ private static void OnIsExpandedChanged(DependencyObject d, DependencyPropertyCh } TreeViewItemAutomationPeer peer = UIElementAutomationPeer.FromElement(item) as TreeViewItemAutomationPeer; - if (peer != null) - { - peer.RaiseExpandCollapseAutomationEvent((bool)e.OldValue, isExpanded); - } + peer?.RaiseExpandCollapseAutomationEvent((bool)e.OldValue, isExpanded); if (isExpanded) { @@ -158,10 +155,7 @@ private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyCh item.Select(isSelected); TreeViewItemAutomationPeer peer = UIElementAutomationPeer.FromElement(item) as TreeViewItemAutomationPeer; - if (peer != null) - { - peer.RaiseAutomationIsSelectedChanged(isSelected); - } + peer?.RaiseAutomationIsSelectedChanged(isSelected); if (isSelected) { @@ -686,9 +680,7 @@ private bool HandleUpDownKey(bool up, KeyEventArgs e) startingContainer = this; } ItemsControl parentItemsControl = ItemsControl.ItemsControlFromItemContainer(this); - ItemInfo startingInfo = (parentItemsControl != null) - ? parentItemsControl.ItemInfoFromContainer(this) - : null; + ItemInfo startingInfo = parentItemsControl?.ItemInfoFromContainer(this); return treeView.NavigateByLine( startingInfo, @@ -738,10 +730,7 @@ private static void OnMouseButtonDown(object sender, MouseButtonEventArgs e) { TreeViewItem tvi = (TreeViewItem)sender; TreeView tv = tvi.ParentTreeView; - if (tv != null) - { - tv.HandleMouseButtonDown(); - } + tv?.HandleMouseButtonDown(); } private static void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e) { @@ -788,10 +777,7 @@ private void HandleBringIntoView(RequestBringIntoViewEventArgs e) private object BringItemIntoView(object args) { FrameworkElement header = HeaderElement; - if (header != null) - { - header.BringIntoView(); - } + header?.BringIntoView(); return null; } @@ -925,10 +911,7 @@ internal void ClearItemContainer(object item, ItemsControl parentItemsControl) // the ItemValueStorage DP for this container. VirtualizingPanel vp = ItemsHost as VirtualizingPanel; - if (vp != null) - { - vp.OnClearChildrenInternal(); - } + vp?.OnClearChildrenInternal(); ItemContainerGenerator.RemoveAllInternal(true /*saveRecycleQueue*/); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/UIElementCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/UIElementCollection.cs index dabb3fcb7cf..849076d51cf 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/UIElementCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/UIElementCollection.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -488,10 +488,7 @@ public virtual IEnumerator GetEnumerator() /// protected void SetLogicalParent(UIElement element) { - if (_logicalParent != null) - { - _logicalParent.AddLogicalChild(element); - } + _logicalParent?.AddLogicalChild(element); } /// @@ -500,10 +497,7 @@ protected void SetLogicalParent(UIElement element) /// protected void ClearLogicalParent(UIElement element) { - if (_logicalParent != null) - { - _logicalParent.RemoveLogicalChild(element); - } + _logicalParent?.RemoveLogicalChild(element); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Validation.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Validation.cs index 9e8f1aa68ad..3e33df4f71a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Validation.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Validation.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -249,10 +249,7 @@ private static void OnValidationAdornerSiteChanged(DependencyObject d, Dependenc DependencyObject oldSite = (DependencyObject)e.OldValue; DependencyObject newSite = (DependencyObject)e.NewValue; - if (oldSite != null) - { - oldSite.ClearValue(ValidationAdornerSiteForProperty); - } + oldSite?.ClearValue(ValidationAdornerSiteForProperty); if (newSite != null) { @@ -315,10 +312,7 @@ private static void OnValidationAdornerSiteForChanged(DependencyObject d, Depend DependencyObject oldSiteFor = (DependencyObject)e.OldValue; DependencyObject newSiteFor = (DependencyObject)e.NewValue; - if (oldSiteFor != null) - { - oldSiteFor.ClearValue(ValidationAdornerSiteProperty); - } + oldSiteFor?.ClearValue(ValidationAdornerSiteProperty); if (newSiteFor != null) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingPanel.cs index f318f96ddba..b230241f48f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingPanel.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -347,10 +347,7 @@ internal static void OnVirtualizationPropertyChanged(DependencyObject d, Depende { p.InvalidateMeasure(); ItemsPresenter itemsPresenter = VisualTreeHelper.GetParent(p) as ItemsPresenter; - if (itemsPresenter != null) - { - itemsPresenter.InvalidateMeasure(); - } + itemsPresenter?.InvalidateMeasure(); if (d is TreeView) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs index 4fcd3453d05..64f01c0f260 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1578,12 +1578,9 @@ public Rect MakeVisible(Visual visual, Rect rectangle) } OnScrollChange(); - if (ScrollOwner != null) - { - // When layout gets updated it may happen that visual is obscured by a ScrollBar - // We call MakeVisible again to make sure element is visible in this case - ScrollOwner.MakeVisible(visual, originalRect); - } + // When layout gets updated it may happen that visual is obscured by a ScrollBar + // We call MakeVisible again to make sure element is visible in this case + ScrollOwner?.MakeVisible(visual, originalRect); } else { @@ -1663,11 +1660,8 @@ protected internal override void BringIndexIntoView(int index) groupItem.UpdateLayout(); VirtualizingPanel itemsHost = groupItem.ItemsHost as VirtualizingPanel; - if (itemsHost != null) - { - // Recursively call child panels until item is found. - itemsHost.BringIndexIntoViewPublic(index); - } + // Recursively call child panels until item is found. + itemsHost?.BringIndexIntoViewPublic(index); } break; } @@ -1998,10 +1992,7 @@ protected virtual void OnCleanUpVirtualizedItem(CleanUpVirtualizedItemEventArgs { ItemsControl itemsControl = ItemsControl.GetItemsOwner(this); - if (itemsControl != null) - { - itemsControl.RaiseEvent(e); - } + itemsControl?.RaiseEvent(e); } #endregion @@ -3116,10 +3107,7 @@ private Size MeasureOverrideImpl(Size constraint, { DependencyObject itemsOwner = itemStorageProvider as DependencyObject; Panel parentPanel = (itemsOwner != null) ? VisualTreeHelper.GetParent(itemsOwner) as Panel : null; - if (parentPanel != null) - { - parentPanel.InvalidateMeasure(); - } + parentPanel?.InvalidateMeasure(); } } @@ -3223,7 +3211,7 @@ private Size MeasureOverrideImpl(Size constraint, SnapshotData data = new SnapshotData { UniformOrAverageContainerSize = uniformOrAverageContainerPixelSize, UniformOrAverageContainerPixelSize = uniformOrAverageContainerPixelSize, - EffectiveOffsets = (effectiveOffsetInfo != null) ? effectiveOffsetInfo.OffsetList : null + EffectiveOffsets = effectiveOffsetInfo?.OffsetList }; SnapshotDataField.SetValue(this, data); } @@ -3523,7 +3511,7 @@ protected override Size ArrangeOverride(Size arrangeSize) SnapshotData data = new SnapshotData { UniformOrAverageContainerSize = uniformOrAverageContainerPixelSize, UniformOrAverageContainerPixelSize = uniformOrAverageContainerPixelSize, - EffectiveOffsets = (effectiveOffsetInfo != null) ? effectiveOffsetInfo.OffsetList : null + EffectiveOffsets = effectiveOffsetInfo?.OffsetList }; SnapshotDataField.SetValue(this, data); @@ -4025,10 +4013,7 @@ protected override void OnClearChildren() CleanupContainers(Int32.MaxValue, Int32.MaxValue, itemsControl); } - if (_realizedChildren != null) - { - _realizedChildren.Clear(); - } + _realizedChildren?.Clear(); InternalChildren.ClearInternal(); } @@ -4067,10 +4052,7 @@ private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArg internal void ClearAllContainers() { IItemContainerGenerator generator = Generator; - if (generator != null) - { - generator.RemoveAll(); - } + generator?.RemoveAll(); } #endregion @@ -4441,10 +4423,7 @@ private void InitializeViewport( // need to remeasure, which should count // as part of the scroll operation DispatcherOperation clearIsScrollActiveOperation = ClearIsScrollActiveOperationField.GetValue(this); - if (clearIsScrollActiveOperation != null) - { - clearIsScrollActiveOperation.Abort(); - } + clearIsScrollActiveOperation?.Abort(); clearIsScrollActiveOperation = Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)ClearIsScrollActive); @@ -5689,7 +5668,7 @@ private double ComputeEffectiveOffset( // giving the child panel the offset it wants the next time this // panel measures the child. EffectiveOffsetInformation effectiveOffsetInformation = EffectiveOffsetInformationField.GetValue(firstContainer); - List childOffsetList = (effectiveOffsetInformation != null) ? effectiveOffsetInformation.OffsetList : null; + List childOffsetList = effectiveOffsetInformation?.OffsetList; if (childOffsetList != null) { int count = childOffsetList.Count; @@ -6450,7 +6429,7 @@ private void SetItemsHostInsetForChild(int index, UIElement child, IContainItemS // this only applies to a hierarchical element with a visible ItemsHost bool isChildHorizontal = isHorizontal; IHierarchicalVirtualizationAndScrollInfo virtualizingChild = GetVirtualizingChild(child, ref isChildHorizontal); - Panel itemsHost = (virtualizingChild == null) ? null : virtualizingChild.ItemsHost; + Panel itemsHost = virtualizingChild?.ItemsHost; if (itemsHost == null || !itemsHost.IsVisible) return; @@ -6520,7 +6499,7 @@ private void SetItemsHostInsetForChild(int index, UIElement child, IContainItemS { // re-measure the scrolling panel ItemsControl scrollingItemsControl = GetScrollingItemsControl(child); - Panel scrollingPanel = (scrollingItemsControl == null) ? null : scrollingItemsControl.ItemsHost; + Panel scrollingPanel = scrollingItemsControl?.ItemsHost; if (scrollingPanel != null) { VirtualizingStackPanel vsp = scrollingPanel as VirtualizingStackPanel; @@ -9577,7 +9556,7 @@ private static void ResetScrolling(VirtualizingStackPanel element) // At the time this method is called, scrolling state is in its new, valid state. private void OnScrollChange() { - if (ScrollOwner != null) { ScrollOwner.InvalidateScrollInfo(); } + ScrollOwner?.InvalidateScrollInfo(); } /// @@ -9857,10 +9836,7 @@ private void SetAndVerifyScrollingData( if (discardOffsets) { // All saved offsets are now meaningless. Discard them. - if (previouslyMeasuredOffsets != null) - { - previouslyMeasuredOffsets.Clear(); - } + previouslyMeasuredOffsets?.Clear(); lastPageSafeOffset = null; lastPagePixelSize = null; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpression.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpression.cs index 3776d136d4a..bdc8fb33108 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpression.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpression.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -193,10 +193,7 @@ public override void UpdateTarget() if (IsDetached) throw new InvalidOperationException(SR.BindingExpressionIsDetached); - if (Worker != null) - { - Worker.RefreshValue(); // calls TransferValue - } + Worker?.RefreshValue(); // calls TransferValue } #region Expression overrides @@ -355,13 +352,13 @@ internal Type ConverterSourceType // the item whose property changes when we UpdateSource internal object SourceItem { - get { return (Worker != null) ? Worker.SourceItem : null; } + get { return Worker?.SourceItem; } } // the name of the property that changes when we UpdateSource internal string SourcePropertyName { - get { return (Worker != null) ? Worker.SourcePropertyName : null; } + get { return Worker?.SourcePropertyName; } } // the value of the source property @@ -1112,8 +1109,7 @@ internal override void Deactivate() CancelPendingTasks(); // detach from data item - if (Worker != null) - Worker.DetachDataItem(); + Worker?.DetachDataItem(); // restore default value, in case source/converter fail to provide a good value ChangeValue(DefaultValueObject, false); @@ -2682,10 +2678,7 @@ internal override void HandlePropertyInvalidation(DependencyObject d, Dependency TransferValue(); } - if (Worker != null) - { - Worker.OnSourceInvalidation(d, dp, args.IsASubPropertyChange); - } + Worker?.OnSourceInvalidation(d, dp, args.IsASubPropertyChange); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpressionBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpressionBase.cs index 83367f5f2a0..82174eb3586 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpressionBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpressionBase.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1314,8 +1314,7 @@ internal void EndSourceUpdate() // When the target is a TextBox with a composition in effect, // do this asynchronously, to avoid confusing the composition's Undo stack System.Windows.Controls.Primitives.TextBoxBase tbb = Target as System.Windows.Controls.Primitives.TextBoxBase; - MS.Internal.Documents.UndoManager undoManager = (tbb == null) ? null : - tbb.TextContainer.UndoManager; + MS.Internal.Documents.UndoManager undoManager = tbb?.TextContainer.UndoManager; if (undoManager != null && undoManager.OpenedUnit != null && undoManager.OpenedUnit.GetType() != typeof(System.Windows.Documents.TextParentUndoUnit)) @@ -1994,7 +1993,7 @@ internal DataBindEngine Engine internal Dispatcher Dispatcher { - get { return (_engine != null) ? _engine.Dispatcher : null; } + get { return _engine?.Dispatcher; } } internal object Value @@ -2047,10 +2046,7 @@ internal virtual bool IsDisconnected internal void Attach(DependencyObject target, DependencyProperty dp) { // make sure we're on the right thread to access the target - if (target != null) - { - target.VerifyAccess(); - } + target?.VerifyAccess(); IsAttaching = true; AttachOverride(target, dp); @@ -2386,10 +2382,7 @@ internal void AddValidationError(ValidationError validationError, bool skipBindi if (!skipBindingGroup) { BindingGroup bindingGroup = BindingGroup; - if (bindingGroup != null) - { - bindingGroup.AddValidationError(validationError); - } + bindingGroup?.AddValidationError(validationError); } } @@ -2402,10 +2395,7 @@ internal void RemoveValidationError(ValidationError validationError, bool skipBi if (!skipBindingGroup) { BindingGroup bindingGroup = BindingGroup; - if (bindingGroup != null) - { - bindingGroup.RemoveValidationError(validationError); - } + bindingGroup?.RemoveValidationError(validationError); } } @@ -2467,8 +2457,7 @@ internal static WeakDependencySource[] CombineSources(int index, { BindingExpressionBase bindExpr = bindingExpressions[i]; WeakDependencySource[] sources = (i==index) ? newSources : - (bindExpr != null) ? bindExpr.WeakSources : - null; + bindExpr?.WeakSources; int m = (sources == null) ? 0 : sources.Length; for (int j = 0; j < m; ++j) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingGroup.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingGroup.cs index dcfe9ac103a..71933686fb2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingGroup.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingGroup.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -338,10 +338,7 @@ public void BeginEdit() for (int i=items.Count-1; i>=0; --i) { IEditableObject ieo = items[i] as IEditableObject; - if (ieo != null) - { - ieo.BeginEdit(); - } + ieo?.BeginEdit(); } IsEditing = true; @@ -382,10 +379,7 @@ public void CancelEdit() for (int i=items.Count-1; i>=0; --i) { IEditableObject ieo = items[i] as IEditableObject; - if (ieo != null) - { - ieo.CancelEdit(); - } + ieo?.CancelEdit(); } // update targets @@ -725,10 +719,7 @@ internal void RemoveProposedValueEntry(ProposedValueEntry entry) internal void AddBindingForProposedValue(BindingExpressionBase dependent, object item, string propertyName) { ProposedValueEntry entry = _proposedValueTable[item, propertyName]; - if (entry != null) - { - entry.AddDependent(dependent); - } + entry?.AddDependent(dependent); } // add a validation error to the mentor's list @@ -869,10 +860,7 @@ void EnsureItems() if (IsEditing) { IEditableObject ieo = newItems[i].Target as IEditableObject; - if (ieo != null) - { - ieo.BeginEdit(); - } + ieo?.BeginEdit(); } // the item may implement INotifyDataErrorInfo diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs index e20bea6c6f5..ecc0c7c1268 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -585,20 +585,14 @@ public object AddNew() MoveCurrentTo(newItem); ISupportInitialize isi = newItem as ISupportInitialize; - if (isi != null) - { - isi.BeginInit(); - } + isi?.BeginInit(); // DataView.AddNew calls BeginEdit on the new item, but other implementations // of IBL don't. Make up for them. if (!IsDataView) { IEditableObject ieo = newItem as IEditableObject; - if (ieo != null) - { - ieo.BeginEdit(); - } + ieo?.BeginEdit(); } return newItem; @@ -757,10 +751,7 @@ object EndAddNew(bool cancel) } ISupportInitialize isi = newItem as ISupportInitialize; - if (isi != null) - { - isi.EndInit(); - } + isi?.EndInit(); return newItem; } @@ -977,10 +968,7 @@ public void EditItem(object item) SetEditItem(item); IEditableObject ieo = item as IEditableObject; - if (ieo != null) - { - ieo.BeginEdit(); - } + ieo?.BeginEdit(); } /// @@ -1051,10 +1039,7 @@ private void ImplicitlyCancelEdit() IEditableObject ieo = _editItem as IEditableObject; SetEditItem(null); - if (ieo != null) - { - ieo.CancelEdit(); - } + ieo?.CancelEdit(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingOperations.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingOperations.cs index 0e88e7e5ac5..87b1c3193bf 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingOperations.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingOperations.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -89,7 +89,7 @@ public static BindingExpressionBase SetBinding(DependencyObject target, Dependen public static BindingBase GetBindingBase(DependencyObject target, DependencyProperty dp) { BindingExpressionBase b = GetBindingExpressionBase(target, dp); - return (b != null) ? b.ParentBindingBase : null; + return b?.ParentBindingBase; } /// @@ -569,10 +569,7 @@ internal static IDisposable EnableExceptionLogging() internal static void LogException(Exception ex) { ExceptionLogger logger = _exceptionLogger; - if (logger != null) - { - logger.LogException(ex); - } + logger?.LogException(ex); } private static ExceptionLogger _exceptionLogger; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionContainer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionContainer.cs index 41bd9722885..0cc623a732b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionContainer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionContainer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -97,10 +97,7 @@ public bool ShouldSerializeCollection() IEnumerator enumerator = Collection.GetEnumerator(); bool result = enumerator.MoveNext(); IDisposable d = enumerator as IDisposable; - if (d != null) - { - d.Dispose(); - } + d?.Dispose(); return result; } @@ -347,8 +344,7 @@ private void HookUpToCollection(IEnumerable newCollection, bool shouldRaiseChang { CollectionChangedEventManager.RemoveHandler(View, OnCollectionChanged); - if (_traceLog != null) - _traceLog.Add("Unsubscribe to CollectionChange from {0}", + _traceLog?.Add("Unsubscribe to CollectionChange from {0}", TraceLog.IdFor(View)); } @@ -363,8 +359,7 @@ private void HookUpToCollection(IEnumerable newCollection, bool shouldRaiseChang { CollectionChangedEventManager.AddHandler(View, OnCollectionChanged); - if (_traceLog != null) - _traceLog.Add("Subscribe to CollectionChange from {0}", TraceLog.IdFor(View)); + _traceLog?.Add("Subscribe to CollectionChange from {0}", TraceLog.IdFor(View)); } if (shouldRaiseChangeEvent) // it's as if this were a refresh of the container's collection diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs index 53a44c03321..f84aef33ce8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -123,10 +123,7 @@ internal CollectionView(IEnumerable collection, int moveToFirst) } IDisposable d = e as IDisposable; - if (d != null) - { - d.Dispose(); - } + d?.Dispose(); }, false); } @@ -1435,10 +1432,7 @@ internal void VerifyRefreshNotDeferred() internal void InvalidateEnumerableWrapper() { IndexedEnumerable wrapper = (IndexedEnumerable) Interlocked.Exchange(ref _enumerableWrapper, null); - if (wrapper != null) - { - wrapper.Invalidate(); - } + wrapper?.Invalidate(); } internal ReadOnlyCollection GetItemProperties() @@ -1576,10 +1570,7 @@ internal object GetRepresentativeItem() } IDisposable d = ie as IDisposable; - if (d != null) - { - d.Dispose(); - } + d?.Dispose(); return result; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionViewSource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionViewSource.cs index 8b731066db5..82fbc50c9f2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionViewSource.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionViewSource.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -949,7 +949,7 @@ void EnsureView(object source, Type collectionViewType) (object x) => { BindingExpressionBase beb = BindingOperations.GetBindingExpressionBase(this, SourceProperty); - return (beb != null) ? beb.GetSourceItem(x) : null; + return beb?.GetSourceItem(x); }); if (viewRecord != null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CompositeCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CompositeCollection.cs index ec4d213b8ff..79893925a18 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CompositeCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CompositeCollection.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -591,10 +591,7 @@ internal void GetCollectionChangedSources(int level, Action @@ -1197,10 +1185,7 @@ public void CommitEdit() IEditableObject ieo = _editItem as IEditableObject; SetEditItem(null); - if (ieo != null) - { - ieo.EndEdit(); - } + ieo?.EndEdit(); // see if the item is entering or leaving the view int fromIndex = InternalIndexOf(editItem); @@ -1220,7 +1205,7 @@ public void CommitEdit() if (isInView) { LiveShapingList lsList = InternalList as LiveShapingList; - LiveShapingItem lsi = (lsList == null) ? null : lsList.ItemAt(lsList.IndexOf(editItem)); + LiveShapingItem lsi = lsList?.ItemAt(lsList.IndexOf(editItem)); AddItemToGroups(editItem, lsi); } return; @@ -1320,10 +1305,7 @@ private void ImplicitlyCancelEdit() IEditableObject ieo = _editItem as IEditableObject; SetEditItem(null); - if (ieo != null) - { - ieo.CancelEdit(); - } + ieo?.CancelEdit(); } /// @@ -1991,7 +1973,7 @@ void ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs } else { - lsi = (lsList == null) ? null : lsList.ItemAt(adjustedNewIndex - delta); + lsi = lsList?.ItemAt(adjustedNewIndex - delta); RemoveItemFromGroups(oldItem); AddItemToGroups(newItem, lsi); } @@ -2062,7 +2044,7 @@ void ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs } else { - lsi = (lsList == null) ? null : lsList.ItemAt(adjustedNewIndex); + lsi = lsList?.ItemAt(adjustedNewIndex); if (simpleMove) { // simple move @@ -2981,7 +2963,7 @@ void PrepareGroups() for (int k=0, n=InternalList.Count; k Send the current value back to the source @@ -88,10 +85,7 @@ public override void UpdateTarget() public override void UpdateSource() { BindingExpressionBase bindExpr = ActiveBindingExpression; - if (bindExpr != null) - { - bindExpr.UpdateSource(); - } + bindExpr?.UpdateSource(); } #region Expression overrides @@ -208,8 +202,7 @@ internal override void DetachOverride() for (int i = 0; i < count; ++i) { BindingExpressionBase b = MutableBindingExpressions[i]; - if (b != null) - b.Detach(); + b?.Detach(); } ChangeSources(null); @@ -410,10 +403,7 @@ internal override bool UpdateSource(BindingGroup bindingGroup) internal override void StoreValueInBindingGroup(object value, BindingGroup bindingGroup) { BindingExpressionBase bindExpr = ActiveBindingExpression; - if (bindExpr != null) - { - bindExpr.StoreValueInBindingGroup(value, bindingGroup); - } + bindExpr?.StoreValueInBindingGroup(value, bindingGroup); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlDataProvider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlDataProvider.cs index 9f19e0bac2e..159222faf6a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlDataProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlDataProvider.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -394,8 +394,7 @@ public XmlSchema GetSchema() public void WriteXml(XmlWriter writer) { XmlDocument doc = _host.DocumentForSerialization; - if (doc != null) - doc.Save(writer); + doc?.Save(writer); } public void ReadXml(XmlReader reader) @@ -435,8 +434,7 @@ private XmlDocument DocumentForSerialization if (_tryInlineDoc || (_savedDocument != null) || (_domSetDocument != null)) { // if inline or assigned doc hasn't been parsed yet, wait for it - if (_waitForInlineDoc != null) - _waitForInlineDoc.WaitOne(); + _waitForInlineDoc?.WaitOne(); return _document; } return null; @@ -459,8 +457,7 @@ private void CreateDocFromInlineXml(XmlReader xmlReader) if (!_tryInlineDoc) { _savedDocument = null; - if (_waitForInlineDoc != null) - _waitForInlineDoc.Set(); + _waitForInlineDoc?.Set(); return; } @@ -504,8 +501,7 @@ private void CreateDocFromInlineXml(XmlReader xmlReader) // If serializer had to wait for the inline doc, it's available now. // If there was an error, null will be returned for DocumentForSerialization. - if (_waitForInlineDoc != null) - _waitForInlineDoc.Set(); + _waitForInlineDoc?.Set(); } // warn the user if the default xmlns wasn't set explicitly (bug 1006946) @@ -719,8 +715,7 @@ private void DiscardInline() { _tryInlineDoc = false; _savedDocument = null; - if (_waitForInlineDoc != null) - _waitForInlineDoc.Set(); + _waitForInlineDoc?.Set(); } private void Hook() diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs index 9239bbf6719..15f6346c4bf 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -55,7 +55,7 @@ internal bool WasVisited(DependencyObject d) { // FrameworkContentElement FrameworkContentElement ancestorFCE = ancestor as FrameworkContentElement; - logicalParent = (ancestorFCE != null) ? ancestorFCE.Parent : null; + logicalParent = ancestorFCE?.Parent; } ancestor = logicalParent; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Adorner.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Adorner.cs index fe77e5ac5a5..3b2fbba4ee8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Adorner.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Adorner.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -74,10 +74,7 @@ protected override Size MeasureOverride(Size constraint) for (int i = 0; i < count; i++) { UIElement ch = this.GetVisualChild(i) as UIElement; - if (ch != null) - { - ch.Measure(desiredSize); - } + ch?.Measure(desiredSize); } return desiredSize; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/AdornerLayer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/AdornerLayer.cs index 483d6298934..5813e8f9a35 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/AdornerLayer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/AdornerLayer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -472,7 +472,7 @@ protected override Size ArrangeOverride(Size finalSize) if (index >= 0) { // Get the matrix transform out, skip all non affine transforms - Transform transform = (adornerTransform != null) ? adornerTransform.AffineTransform : null; + Transform transform = adornerTransform?.AffineTransform; ((Adorner)(_children[index])).AdornerTransform = transform; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/AnchoredBlock.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/AnchoredBlock.cs index 7cb6068d3a4..fdf50342653 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/AnchoredBlock.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/AnchoredBlock.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -45,17 +45,11 @@ public abstract class AnchoredBlock : Inline /// protected AnchoredBlock(Block block, TextPointer insertionPosition) { - if (insertionPosition != null) - { - insertionPosition.TextContainer.BeginChange(); - } + insertionPosition?.TextContainer.BeginChange(); try { - if (insertionPosition != null) - { - // This will throw InvalidOperationException if schema validity is violated. - insertionPosition.InsertInline(this); - } + // This will throw InvalidOperationException if schema validity is violated. + insertionPosition?.InsertInline(this); if (block != null) { @@ -64,10 +58,7 @@ protected AnchoredBlock(Block block, TextPointer insertionPosition) } finally { - if (insertionPosition != null) - { - insertionPosition.TextContainer.EndChange(); - } + insertionPosition?.TextContainer.EndChange(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs index 02c3d87a913..9ea37f41795 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -860,11 +860,8 @@ private void EnsureAttachedToView() if (layer == null) { // There is no AdornerLayer available. Clear cached value and exit. - if (_adornerLayer != null) - { - // We're currently in a layer that doesn't exist. - _adornerLayer.Remove(this); - } + // We're currently in a layer that doesn't exist. + _adornerLayer?.Remove(this); _adornerLayer = null; return; @@ -876,11 +873,8 @@ private void EnsureAttachedToView() return; } - if (_adornerLayer != null) - { - // We're currently in the wrong layer. - _adornerLayer.Remove(this); - } + // We're currently in the wrong layer. + _adornerLayer?.Remove(this); // Add ourselves to the correct layer. _adornerLayer = layer; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ColumnResizeAdorner.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ColumnResizeAdorner.cs index 67c4f4d5d01..eacec87556c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ColumnResizeAdorner.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ColumnResizeAdorner.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -134,10 +134,7 @@ internal void Initialize(UIElement renderScope, double xPos, double yPos, double _adornerLayer = AdornerLayer.GetAdornerLayer(renderScope); - if (_adornerLayer != null) - { - _adornerLayer.Add(this); - } + _adornerLayer?.Add(this); _x = xPos; _top = yPos; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CompositionAdorner.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CompositionAdorner.cs index ada5b11dc1a..7a398e5077c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CompositionAdorner.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CompositionAdorner.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -362,11 +362,8 @@ internal void Initialize(ITextView textView) _adornerLayer = AdornerLayer.GetAdornerLayer(textView.RenderScope); - if (_adornerLayer != null) - { - // Add the CompositionAdorner to the scoping of AdornerLayer - _adornerLayer.Add(this); - } + // Add the CompositionAdorner to the scoping of AdornerLayer + _adornerLayer?.Add(this); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs index e0351f639da..5d2d290e159 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -355,10 +355,7 @@ internal void CancelAsync(object userState) if (asyncRequest != null) { asyncRequest.Cancelled = true; - if (asyncRequest.Page.ChildPaginator != null) - { - asyncRequest.Page.ChildPaginator.CancelAsync(asyncRequest); - } + asyncRequest.Page.ChildPaginator?.CancelAsync(asyncRequest); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequenceTextView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequenceTextView.cs index 455cf1eba43..64463b23831 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequenceTextView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequenceTextView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -455,10 +455,7 @@ internal override bool Contains(ITextPointer position) /// internal override bool Validate() { - if (ChildTextView != null) - { - ChildTextView.Validate(); - } + ChildTextView?.Validate(); return ((ITextView)this).IsValid; } @@ -466,10 +463,7 @@ internal override bool Validate() /// internal override bool Validate(Point point) { - if (ChildTextView != null) - { - ChildTextView.Validate(point); - } + ChildTextView?.Validate(point); return ((ITextView)this).IsValid; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs index 695ad26237f..afaa473fd42 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1169,10 +1169,7 @@ private void OnHighlightChanged(object sender, HighlightChangedEventArgs args) { HighlightVisual hv = HighlightVisual.GetHighlightVisual(SyncGetPage(i, false /*forceReload*/)); - if (hv != null) - { - hv.InvalidateHighlights(); - } + hv?.InvalidateHighlights(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedFindEngine.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedFindEngine.cs index 506ee22f5f3..57d547f84a3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedFindEngine.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedFindEngine.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -73,10 +73,7 @@ internal static TextRange Find ( ITextPointer start, FixedDocumentSequence documentSequence = paginatorSource as FixedDocumentSequence; DynamicDocumentPaginator childPaginator = null; - if (documentSequence != null) - { - documentSequence.TranslatePageNumber(pageNumber, out childPaginator, out translatedPageNumber); - } + documentSequence?.TranslatePageNumber(pageNumber, out childPaginator, out translatedPageNumber); if (pageNumber - endPageNumber != 0) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs index 2fff300666f..492c0be75c8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -852,10 +852,7 @@ private GlyphComparison _CompareGlyphs(Glyphs glyph1, Glyphs glyph2) GeneralTransform transform = glyph2.TransformToVisual(glyph1); Point prevPt = LTR1 ? box1.TopRight : box1.TopLeft; Point currentPt = LTR2 ? box2.TopLeft : box2.TopRight; - if (transform != null) - { - transform.TryTransform(currentPt, out currentPt); - } + transform?.TryTransform(currentPt, out currentPt); if (IsSameLine(currentPt.Y - prevPt.Y, box1.Height, box2.Height)) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs index a1f169470fb..c994865bfd0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -770,7 +770,7 @@ private bool _HitTest(Point pt, out UIElement e) e = null; HitTestResult result = VisualTreeHelper.HitTest(this.FixedPage, pt); - DependencyObject v = (result != null) ? result.VisualHit : null; + DependencyObject v = result?.VisualHit; while (v != null) { @@ -828,10 +828,7 @@ private ITextPointer _SnapToText(Point point) Glyphs startGlyphs = this.FixedPage.GetGlyphsElement(node); GeneralTransform tranToGlyphs = this.FixedPage.TransformToDescendant(startGlyphs); Point transformedPt = point; - if (tranToGlyphs != null) - { - tranToGlyphs.TryTransform(transformedPt, out transformedPt); - } + tranToGlyphs?.TryTransform(transformedPt, out transformedPt); GlyphRun run = startGlyphs.ToGlyphRun(); Rect alignmentRect = run.ComputeAlignmentBox(); @@ -1184,10 +1181,7 @@ private ITextPointer _CreateTextPointer(FixedPosition fixedPosition, LogicalDire private ITextPointer _CreateTextPointerFromGlyphs(Glyphs g, Point point) { GeneralTransform transform = this.VisualRoot.TransformToDescendant(g); - if (transform != null) - { - transform.TryTransform(point, out point); - } + transform?.TryTransform(point, out point); int charIndex; LogicalDirection edge; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs index 5824acd693b..cb6617b0b0f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -803,10 +803,7 @@ protected sealed override void OnPropertyChanged(DependencyPropertyChangedEventA _structuralCache.InvalidateFormatCache(!affectsRender); // Notify formatter about content invalidation. - if (_formatter != null) - { - _formatter.OnContentInvalidated(!affectsRender); - } + _formatter?.OnContentInvalidated(!affectsRender); } } } @@ -968,10 +965,7 @@ internal void OnChildDesiredSizeChanged(UIElement child) _structuralCache.AddDirtyTextRange(dtr); // Notify formatter about content invalidation. - if (_formatter != null) - { - _formatter.OnContentInvalidated(true, childStart, childEnd); - } + _formatter?.OnContentInvalidated(true, childStart, childEnd); } } @@ -1242,13 +1236,10 @@ private static void OnPageMetricsChanged(DependencyObject d, DependencyPropertyC if (fd._structuralCache != null && fd._structuralCache.IsFormattedOnce) { // Notify formatter about content invalidation. - if (fd._formatter != null) - { - // Any change of page metrics invalidates the layout. - // Hence page metrics change is treated in the same way as ContentChanged - // spanning entire content. - fd._formatter.OnContentInvalidated(true); - } + // Any change of page metrics invalidates the layout. + // Hence page metrics change is treated in the same way as ContentChanged + // spanning entire content. + fd._formatter?.OnContentInvalidated(true); // Fire notification about the PageSize change - needed in RichTextBox if (fd.PageSizeChanged != null) @@ -1510,10 +1501,7 @@ private void OnTextContainerChange(object sender, TextContainerChangeEventArgs a } // Notify formatter about content invalidation. - if (_formatter != null) - { - _formatter.OnContentInvalidated(!args.AffectsRenderOnly, args.ITextPosition, segmentEnd); - } + _formatter?.OnContentInvalidated(!args.AffectsRenderOnly, args.ITextPosition, segmentEnd); } finally { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs index bb46398a91b..db4635a835f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -98,8 +98,7 @@ protected override Size ArrangeOverride(Size finalSize) { base.ArrangeOverride(finalSize); - if (_measurementGlyphRun != null) - _measurementGlyphRun.ComputeInkBoundingBox(); + _measurementGlyphRun?.ComputeInkBoundingBox(); return finalSize; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Hyperlink.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Hyperlink.cs index 4ef38efc19e..d1fb6537a9f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Hyperlink.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Hyperlink.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -679,8 +679,7 @@ protected virtual void OnClick() if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { AutomationPeer peer = ContentElementAutomationPeer.CreatePeerForElement(this); - if (peer != null) - peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); + peer?.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } DoNavigation(this); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs index 931aefdf4cf..16b55be7524 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1859,12 +1859,12 @@ private void OnTextContainerChange(object sender, TextContainerChangeEventArgs a private UIElement RenderScope { - get { return _editor.TextView == null ? null : _editor.TextView.RenderScope; } + get { return _editor.TextView?.RenderScope; } } private FrameworkElement UiScope { - get { return (_editor == null) ? null : _editor.UiScope; } + get { return _editor?.UiScope; } } private bool IsReadOnly diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineUIContainer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineUIContainer.cs index 802f35a2e02..df645d90f8f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineUIContainer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineUIContainer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -62,26 +62,17 @@ public InlineUIContainer(UIElement childUIElement) : this(childUIElement, null) /// public InlineUIContainer(UIElement childUIElement, TextPointer insertionPosition) { - if (insertionPosition != null) - { - insertionPosition.TextContainer.BeginChange(); - } + insertionPosition?.TextContainer.BeginChange(); try { - if (insertionPosition != null) - { - // This will throw InvalidOperationException if schema validity is violated. - insertionPosition.InsertInline(this); - } + // This will throw InvalidOperationException if schema validity is violated. + insertionPosition?.InsertInline(this); this.Child = childUIElement; } finally { - if (insertionPosition != null) - { - insertionPosition.TextContainer.EndChange(); - } + insertionPosition?.TextContainer.EndChange(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/LineBreak.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/LineBreak.cs index 63716273f50..79596e5b9ec 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/LineBreak.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/LineBreak.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -32,24 +32,15 @@ public LineBreak() /// public LineBreak(TextPointer insertionPosition) { - if (insertionPosition != null) - { - insertionPosition.TextContainer.BeginChange(); - } + insertionPosition?.TextContainer.BeginChange(); try { - if (insertionPosition != null) - { - // This will throw InvalidOperationException if schema validity is violated. - insertionPosition.InsertInline(this); - } + // This will throw InvalidOperationException if schema validity is violated. + insertionPosition?.InsertInline(this); } finally { - if (insertionPosition != null) - { - insertionPosition.TextContainer.EndChange(); - } + insertionPosition?.TextContainer.EndChange(); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/MsSpellCheckLib/SpellChecker/SpellChecker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/MsSpellCheckLib/SpellChecker/SpellChecker.cs index 22c31083a4c..c9ea2b88d92 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/MsSpellCheckLib/SpellChecker/SpellChecker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/MsSpellCheckLib/SpellChecker/SpellChecker.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -86,9 +86,7 @@ public List SuggestImpl(string word) IEnumString suggestions = _speller.Value.Suggest(word); return - suggestions != null ? - suggestions.ToList(shouldSuppressCOMExceptions:false, shouldReleaseCOMObject:true) : - null; + suggestions?.ToList(shouldSuppressCOMExceptions:false, shouldReleaseCOMObject:true); } public List SuggestImplWithRetries(string word, bool shouldSuppressCOMExceptions = true) @@ -218,7 +216,7 @@ public byte GetOptionValue(string optionId, bool suppressCOMExceptions = true) private List GetOptionIdsImpl() { IEnumString optionIds = _speller.Value.OptionIds; - return (optionIds != null) ? optionIds.ToList(false, true) : null; + return optionIds?.ToList(false, true); } private List GetOptionIdsImplWithRetries(bool suppressCOMExceptions) @@ -328,7 +326,7 @@ public OptionDescription GetOptionDescription(string optionId, bool suppressCOME private List CheckImpl(string text) { IEnumSpellingError errors = _speller.Value.Check(text); - return (errors != null) ? errors.ToList(this, text, false, true) : null; + return errors?.ToList(this, text, false, true); } private List CheckImplWithRetries(string text, bool suppressCOMExceptions) @@ -356,7 +354,7 @@ public List Check(string text, bool suppressCOMExceptions = true) public List ComprehensiveCheckImpl(string text) { IEnumSpellingError errors = _speller.Value.ComprehensiveCheck(text); - return (errors != null) ? errors.ToList(this, text, false, true) : null; + return errors?.ToList(this, text, false, true); } public List ComprehensiveCheckImplWithRetries(string text, bool shouldSuppressCOMExceptions = true) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs index 7061dcf86fd..acd7ac5e558 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -73,10 +73,7 @@ public FixedPage GetPageRoot(bool forceReload) #endif // VerifyAccess(); - if (_asyncOp != null) - { - _asyncOp.Wait(); - } + _asyncOp?.Wait(); FixedPage p = null; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs index 2286785949b..8d8fca177e0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -7327,7 +7327,7 @@ private void PreCoalesceRow(DocumentNode dn, ref bool fVMerged) DocumentNodeArray dnaCells = dn.GetRowsCells(); RowFormat rf = dn.FormatState.RowFormat; DocumentNode dnTable = dn.GetParentOfType(DocumentNodeType.dnTable); - ColumnStateArray csa = (dnTable != null) ? dnTable.ColumnStateArray : null; + ColumnStateArray csa = dnTable?.ColumnStateArray; // Normally number of cells and cell definitions are equal, but be careful. int nCount = dnaCells.Count < rf.CellCount ? dnaCells.Count : rf.CellCount; @@ -10929,11 +10929,8 @@ internal void HandleTableProperties(RtfToken token, FormatState formatState) break; case RtfControlWord.Ctrl_BRDRNONE: // No borders - if (ConverterState.CurrentBorder != null) - { - // Note that propset does validation - ConverterState.CurrentBorder.SetDefaults(); - } + // Note that propset does validation + ConverterState.CurrentBorder?.SetDefaults(); break; case RtfControlWord.Ctrl_BRDRWAVY: // Wavy border diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RubberbandSelector.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RubberbandSelector.cs index d365b60faf9..3c9f88d5564 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RubberbandSelector.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RubberbandSelector.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -143,10 +143,7 @@ private void UpdateHighlightVisual(FixedPage page) if (page != null) { HighlightVisual hv = HighlightVisual.GetHighlightVisual(page); - if (hv != null) - { - hv.UpdateRubberbandSelection(this); - } + hv?.UpdateRubberbandSelection(this); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Run.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Run.cs index 28f9db1d7ad..84164f3e572 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Run.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Run.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -56,17 +56,11 @@ public Run(string text) : this(text, null) /// public Run(string text, TextPointer insertionPosition) { - if (insertionPosition != null) - { - insertionPosition.TextContainer.BeginChange(); - } + insertionPosition?.TextContainer.BeginChange(); try { - if (insertionPosition != null) - { - // This will throw InvalidOperationException if schema validity is violated. - insertionPosition.InsertInline(this); - } + // This will throw InvalidOperationException if schema validity is violated. + insertionPosition?.InsertInline(this); if (text != null) { @@ -77,10 +71,7 @@ public Run(string text, TextPointer insertionPosition) } finally { - if (insertionPosition != null) - { - insertionPosition.TextContainer.EndChange(); - } + insertionPosition?.TextContainer.EndChange(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Span.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Span.cs index abf639616a6..2b4dc754f3c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Span.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Span.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -54,17 +54,11 @@ public Span(Inline childInline) : this(childInline, null) /// public Span(Inline childInline, TextPointer insertionPosition) { - if (insertionPosition != null) - { - insertionPosition.TextContainer.BeginChange(); - } + insertionPosition?.TextContainer.BeginChange(); try { - if (insertionPosition != null) - { - // This will throw InvalidOperationException if schema validity is violated. - insertionPosition.InsertInline(this); - } + // This will throw InvalidOperationException if schema validity is violated. + insertionPosition?.InsertInline(this); if (childInline != null) { @@ -73,10 +67,7 @@ public Span(Inline childInline, TextPointer insertionPosition) } finally { - if (insertionPosition != null) - { - insertionPosition.TextContainer.EndChange(); - } + insertionPosition?.TextContainer.EndChange(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Speller.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Speller.cs index 7d282900966..8bbc5816b8a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Speller.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Speller.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -166,7 +166,7 @@ internal ITextPointer GetNextSpellingErrorPosition(ITextPointer position, Logica } SpellingError spellingError = GetError(position, direction, false /* forceEvaluation */); - return spellingError == null ? null : spellingError.Start; + return spellingError?.Start; } // Called by SpellingError to retreive a list of suggestions @@ -511,10 +511,7 @@ private void OnTextContainerChange(object sender, TextContainerChangeEventArgs e return; } - if (_statusTable != null) - { - _statusTable.OnTextChange(e); - } + _statusTable?.OnTextChange(e); ScheduleIdleCallback(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/SplayTreeNode.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/SplayTreeNode.cs index ef8efb96884..1a3cd549591 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/SplayTreeNode.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/SplayTreeNode.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -214,11 +214,8 @@ internal SplayTreeNode GetPreviousNode() } } - if (previousNode != null) - { - // Splay to keep the tree balanced. - previousNode.Splay(); - } + // Splay to keep the tree balanced. + previousNode?.Splay(); return previousNode; } @@ -267,11 +264,8 @@ internal SplayTreeNode GetNextNode() } } - if (nextNode != null) - { - // Splay to keep the tree balanced. - nextNode.Splay(); - } + // Splay to keep the tree balanced. + nextNode?.Splay(); return nextNode; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Table.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Table.cs index 6f651f4b2ae..a63560e2952 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Table.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Table.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -260,10 +260,7 @@ internal void OnStructureChanged() // Table structure changes affect number of rows and colums. Need to notify peer about it. TableAutomationPeer peer = ContentElementAutomationPeer.FromElement(this) as TableAutomationPeer; - if (peer != null) - { - peer.OnStructureInvalidated(); - } + peer?.OnStructureInvalidated(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableCell.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableCell.cs index c3e4f02cd0d..84a0b950f8f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableCell.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableCell.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -323,10 +323,7 @@ int IIndexedChild.Index /// internal void OnEnterParentTree() { - if(Table != null) - { - Table.OnStructureChanged(); - } + Table?.OnStructureChanged(); } /// @@ -341,10 +338,7 @@ internal void OnExitParentTree() /// internal void OnAfterExitParentTree(TableRow row) { - if(row.Table != null) - { - row.Table.OnStructureChanged(); - } + row.Table?.OnStructureChanged(); } @@ -377,7 +371,7 @@ internal void ValidateStructure(int columnIndex) /// /// Table owner accessor /// - internal Table Table { get { return Row != null ? Row.Table : null; } } + internal Table Table { get { return Row?.Table; } } /// /// Cell's index in the parents collection. @@ -566,17 +560,11 @@ private static void OnColumnSpanChanged(DependencyObject d, DependencyPropertyCh { TableCell cell = (TableCell) d; - if(cell.Table != null) - { - cell.Table.OnStructureChanged(); - } + cell.Table?.OnStructureChanged(); // Update AutomaitonPeer. TableCellAutomationPeer peer = ContentElementAutomationPeer.FromElement(cell) as TableCellAutomationPeer; - if (peer != null) - { - peer.OnColumnSpanChanged((int)e.OldValue, (int)e.NewValue); - } + peer?.OnColumnSpanChanged((int)e.OldValue, (int)e.NewValue); } /// @@ -586,17 +574,11 @@ private static void OnRowSpanChanged(DependencyObject d, DependencyPropertyChang { TableCell cell = (TableCell) d; - if(cell.Table != null) - { - cell.Table.OnStructureChanged(); - } + cell.Table?.OnStructureChanged(); // Update AutomaitonPeer. TableCellAutomationPeer peer = ContentElementAutomationPeer.FromElement(cell) as TableCellAutomationPeer; - if (peer != null) - { - peer.OnRowSpanChanged((int)e.OldValue, (int)e.NewValue); - } + peer?.OnRowSpanChanged((int)e.OldValue, (int)e.NewValue); } #endregion Property Invalidation diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableColumn.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableColumn.cs index 9cba4da2cdf..4cf83fa8cba 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableColumn.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableColumn.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -263,10 +263,7 @@ private static bool IsValidWidth(object value) private static void OnWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Table table = ((TableColumn) d).Table; - if(table != null) - { - table.InvalidateColumns(); - } + table?.InvalidateColumns(); } /// @@ -275,10 +272,7 @@ private static void OnWidthChanged(DependencyObject d, DependencyPropertyChanged private static void OnBackgroundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Table table = ((TableColumn) d).Table; - if(table != null) - { - table.InvalidateColumns(); - } + table?.InvalidateColumns(); } #endregion Static Initialization diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableRow.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableRow.cs index db04d249d6c..a8ddc7791d8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableRow.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableRow.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -155,10 +155,7 @@ int IIndexedChild.Index /// internal void OnEnterParentTree() { - if (Table != null) - { - Table.OnStructureChanged(); - } + Table?.OnStructureChanged(); } /// @@ -269,7 +266,7 @@ internal TableRowGroup RowGroup /// /// Table owner accessor /// - internal Table Table { get { return (RowGroup != null ? RowGroup.Table : null); } } + internal Table Table { get { return (RowGroup?.Table); } } /// /// Returns the row's cell collection diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableRowGroup.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableRowGroup.cs index 3c86c46dd9c..20d7ff54a00 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableRowGroup.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableRowGroup.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -174,10 +174,7 @@ int IIndexedChild.Index /// internal void OnEnterParentTree() { - if(Table != null) - { - Table.OnStructureChanged(); - } + Table?.OnStructureChanged(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextContainer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextContainer.cs index b2775d5210c..f99ee3ded10 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextContainer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextContainer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -920,10 +920,7 @@ internal void InsertTextInternal(TextPointer position, object text) // Notify the TextElement of a content change. TextElement textElement = position.Parent as TextElement; - if (textElement != null) - { - textElement.OnTextUpdated(); - } + textElement?.OnTextUpdated(); } // InsertElement worker. Adds a TextElement to the tree. @@ -1257,10 +1254,7 @@ internal void DeleteContentInternal(TextPointer startPosition, TextPointer endPo Invariant.Assert(symbolCount > 0); - if (undoUnit != null) - { - undoUnit.SetTreeHashCode(); - } + undoUnit?.SetTreeHashCode(); // Public tree event. deletePosition = new TextPointer(startPosition, LogicalDirection.Forward); @@ -2093,10 +2087,7 @@ private void ReparentLogicalChildren(SplayTreeNode firstChildNode, SplayTreeNode } TextElement textElement = logicalTreeNode as TextElement; - if (textElement != null) - { - textElement.BeforeLogicalTreeChange(); - } + textElement?.BeforeLogicalTreeChange(); try { @@ -2112,10 +2103,7 @@ private void ReparentLogicalChildren(SplayTreeNode firstChildNode, SplayTreeNode } finally { - if (textElement != null) - { - textElement.AfterLogicalTreeChange(); - } + textElement?.AfterLogicalTreeChange(); } if (node == lastChildNode) @@ -2351,14 +2339,8 @@ private int DeleteContentFromSiblingTree(SplayTreeNode containingNode, TextPoint // Make sure left/rightSubTree stay local roots, we might // have inserted new elements in the AdjustRefCountsForContentDelete call. - if (leftSubTree != null) - { - leftSubTree.Splay(); - } - if (rightSubTree != null) - { - rightSubTree.Splay(); - } + leftSubTree?.Splay(); + rightSubTree?.Splay(); // Similarly, middleSubtree might not be a local root any more, // so splay it too. middleSubTree.Splay(); @@ -2397,10 +2379,7 @@ private int DeleteContentFromSiblingTree(SplayTreeNode containingNode, TextPoint // their contents. Invariant.Assert(startPosition.Parent == endPosition.Parent); TextElement textElement = startPosition.Parent as TextElement; - if (textElement != null) - { - textElement.OnTextUpdated(); - } + textElement?.OnTextUpdated(); } return symbolCount; @@ -2729,12 +2708,9 @@ private int CutContent(TextPointer startPosition, TextPointer endPosition, out i } } - if (rightSubTree != null) - { - // Make sure rightSubTree is a root before returning. - // We haven't done anything yet to ensure this. - rightSubTree.Splay(); - } + // Make sure rightSubTree is a root before returning. + // We haven't done anything yet to ensure this. + rightSubTree?.Splay(); Invariant.Assert(leftSubTree == null || leftSubTree.Role == SplayTreeNodeRole.LocalRoot); Invariant.Assert(middleSubTree == null || middleSubTree.Role == SplayTreeNodeRole.LocalRoot); @@ -2904,10 +2880,7 @@ private char[] ExtractElementInternal(TextElement element, bool deep, out Extrac NextGeneration(true /* deletedContent */); - if (undoUnit != null) - { - undoUnit.SetTreeHashCode(); - } + undoUnit?.SetTreeHashCode(); // Raise the public event. if (deep) @@ -3475,7 +3448,7 @@ private Dispatcher Dispatcher { get { - return (this.Parent != null) ? this.Parent.Dispatcher : null; + return this.Parent?.Dispatcher; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs index 4ce474e8ac8..c45483ad0f1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -288,10 +288,7 @@ internal void SetCustomDictionaries(bool add) // Forwards a spelling reform property change off to the speller. internal void SetSpellingReform(SpellingReform spellingReform) { - if (_speller != null) - { - _speller.SetSpellingReform(spellingReform); - } + _speller?.SetSpellingReform(spellingReform); } // Queries a FrameworkElement for its TextView @@ -307,7 +304,7 @@ internal static ITextSelection GetTextSelection(FrameworkElement frameworkElemen { TextEditor textEditor = TextEditor._GetTextEditor(frameworkElement); - return (textEditor == null) ? null : textEditor.Selection; + return textEditor?.Selection; } // Registers all text editing command handlers for a given control type @@ -1281,15 +1278,9 @@ internal bool _IsSourceInScope(object source) /// internal void CompleteComposition() { - if (TextStore != null) - { - TextStore.CompleteComposition(); - } + TextStore?.CompleteComposition(); - if (ImmComposition != null) - { - ImmComposition.CompleteComposition(); - } + ImmComposition?.CompleteComposition(); } #endregion Class Internal Methods @@ -1612,18 +1603,12 @@ private object OnTextViewUpdatedWorker(object o) return null; } - if (_textstore != null) - { - _textstore.OnLayoutUpdated(); - } + _textstore?.OnLayoutUpdated(); // IMM32's OnLostFocus handler. Clean the composition string if it exists. if (_immEnabled) { - if (_immComposition != null) - { - _immComposition.OnLayoutUpdated(); - } + _immComposition?.OnLayoutUpdated(); } return null; @@ -1701,10 +1686,7 @@ private static void OnGotKeyboardFocus(object sender, KeyboardFocusChangedEventA } // Cicero's OnGotKeyboardFocus handler. It updates the focus DIM. - if (This._textstore != null) - { - This._textstore.OnGotFocus(); - } + This._textstore?.OnGotFocus(); // IMM32's OnGotFocus handler. Ready for the composition string. if (_immEnabled) @@ -1759,10 +1741,7 @@ private static void OnLostKeyboardFocus(object sender, KeyboardFocusChangedEvent This._selection.UpdateCaretAndHighlight(); // Call the TextStore's OnLostfocus handler. Finalizes the curernt composition, if any. - if (This._textstore != null) - { - This._textstore.OnLostFocus(); - } + This._textstore?.OnLostFocus(); // IMM32's OnLostFocus handler. Clean the composition string if it exists. if (_immEnabled) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorMouse.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorMouse.cs index b53f2c9937e..a39d206253f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorMouse.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorMouse.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -133,10 +133,7 @@ internal static bool IsPointWithinInteractiveArea(TextEditor textEditor, Point p { // Transform point to TextView.RenderScope coordinates. transform = textEditor.UiScope.TransformToDescendant(textEditor.TextView.RenderScope); - if (transform != null) - { - transform.TryTransform(point, out point); - } + transform?.TryTransform(point, out point); position = textEditor.TextView.GetTextPositionFromPoint(point, true); interactiveArea = (position != null); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorSpelling.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorSpelling.cs index 4cae5782180..6fbee7fc5d5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorSpelling.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorSpelling.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -35,7 +35,7 @@ internal static void _RegisterClassHandlers(Type controlType, bool registerEvent // Worker for TextBox/RichTextBox.GetSpellingErrorAtPosition. internal static SpellingError GetSpellingErrorAtPosition(TextEditor This, ITextPointer position, LogicalDirection direction) { - return (This.Speller == null) ? null : This.Speller.GetError(position, direction, true /* forceEvaluation */); + return This.Speller?.GetError(position, direction, true /* forceEvaluation */); } // Returns the error (if any) at the current selection. @@ -100,7 +100,7 @@ internal static SpellingError GetSpellingErrorAtSelection(TextEditor This) // Worker for TextBox/RichTextBox.GetNextSpellingErrorPosition. internal static ITextPointer GetNextSpellingErrorPosition(TextEditor This, ITextPointer position, LogicalDirection direction) { - return (This.Speller == null) ? null : This.Speller.GetNextSpellingErrorPosition(position, direction); + return This.Speller?.GetNextSpellingErrorPosition(position, direction); } #endregion Class Internal Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorTyping.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorTyping.cs index 4e230ede6dd..106c5c1b5c7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorTyping.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorTyping.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -147,10 +147,7 @@ internal static void _FlushPendingInputItems(TextEditor This) { TextEditorThreadLocalStore threadLocalStore; - if (This.TextView != null) - { - This.TextView.ThrottleBackgroundTasksForUserInput(); - } + This.TextView?.ThrottleBackgroundTasksForUserInput(); threadLocalStore = TextEditor._ThreadLocalStore; @@ -376,10 +373,7 @@ internal static void OnTextInput(object sender, TextCompositionEventArgs e) // Consider event handled e.Handled = true; - if (This.TextView != null) - { - This.TextView.ThrottleBackgroundTasksForUserInput(); - } + This.TextView?.ThrottleBackgroundTasksForUserInput(); // If this event is our Cicero TextStore composition, we always handles through ITextStore::SetText. if (composition != null) @@ -455,10 +449,7 @@ private static void OnCorrectionList(object target, ExecutedRoutedEventArgs args return; } - if (This.TextStore != null) - { - This.TextStore.QueryRangeOrReconvertSelection( /*fDoReconvert:*/ true); - } + This.TextStore?.QueryRangeOrReconvertSelection( /*fDoReconvert:*/ true); } /// @@ -1283,10 +1274,7 @@ private static void OnSpace(object sender, ExecutedRoutedEventArgs e) // Consider event handled e.Handled = true; - if (This.TextView != null) - { - This.TextView.ThrottleBackgroundTasksForUserInput(); - } + This.TextView?.ThrottleBackgroundTasksForUserInput(); ScheduleInput(This, new TextInputItem(This, " ", /*isInsertKeyToggled:*/!This._OvertypeMode)); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs index e81140b3227..f24e5bc0a68 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1108,10 +1108,7 @@ internal void DeepEndInit() // child.Current could be FrameworkElement, FrameworkContentElement, // or anything else. Only recursively call self for FE & FCE. TextElement child = children.Current as TextElement; - if (child != null) - { - child.DeepEndInit(); - } + child?.DeepEndInit(); } } @@ -1425,7 +1422,7 @@ internal TextElement NextElement } TextTreeTextElementNode node = _textElementNode.GetNextNode() as TextTreeTextElementNode; - return (node != null) ? node.TextElement : null; + return node?.TextElement; } } @@ -1443,7 +1440,7 @@ internal TextElement PreviousElement } TextTreeTextElementNode node = _textElementNode.GetPreviousNode() as TextTreeTextElementNode; - return (node != null) ? node.TextElement : null; + return node?.TextElement; } } @@ -1461,7 +1458,7 @@ internal TextElement FirstChildElement } TextTreeTextElementNode node = _textElementNode.GetFirstContainedNode() as TextTreeTextElementNode; - return (node != null) ? node.TextElement : null; + return node?.TextElement; } } @@ -1479,7 +1476,7 @@ internal TextElement LastChildElement } TextTreeTextElementNode node = _textElementNode.GetLastContainedNode() as TextTreeTextElementNode; - return (node != null) ? node.TextElement : null; + return node?.TextElement; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElementCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElementCollection.cs index e6fd5a43dca..695368a8b16 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElementCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElementCollection.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -720,7 +720,7 @@ internal TextElementType FirstChild else { TextTreeTextElementNode node = this.TextContainer.FirstContainedNode as TextTreeTextElementNode; - firstChild = (TextElementType)(node == null ? null : node.TextElement); + firstChild = (TextElementType)(node?.TextElement); } return firstChild; @@ -743,7 +743,7 @@ internal TextElementType LastChild else { TextTreeTextElementNode node = this.TextContainer.LastContainedNode as TextTreeTextElementNode; - lastChild = (TextElementType)(node == null ? null : node.TextElement); + lastChild = (TextElementType)(node?.TextElement); } return lastChild; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextPointer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextPointer.cs index df3402f0edb..1722fbc64d0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextPointer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextPointer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -2168,7 +2168,7 @@ internal TextElement GetAdjacentElementFromOuterPosition(LogicalDirection direct SyncToTreeGeneration(); elementNode = GetAdjacentTextElementNodeSibling(direction); - return (elementNode == null) ? null : elementNode.TextElement; + return elementNode?.TextElement; } /// @@ -2418,7 +2418,7 @@ Type ITextPointer.GetElementType(LogicalDirection direction) element = GetElement(direction); - return element != null ? element.GetType() : null; + return element?.GetType(); } bool ITextPointer.HasEqualScope(ITextPointer position) @@ -3616,7 +3616,7 @@ Type ITextPointer.ParentType DependencyObject element = this.Parent; - return element != null ? element.GetType() : null; + return element?.GetType(); } } @@ -4122,7 +4122,7 @@ private TextElement GetElement(LogicalDirection direction) elementNode = GetAdjacentTextElementNode(direction); - return (elementNode == null) ? null : elementNode.TextElement; + return elementNode?.TextElement; } // Invariant.Strict only. Asserts this position has good state. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSelection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSelection.cs index 4729eef70af..7f18e8d26cc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSelection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSelection.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -207,14 +207,8 @@ bool ITextRange._IsChanged // from false to true. if (!_IsChanged && value) { - if (this.TextStore != null) - { - this.TextStore.OnSelectionChange(); - } - if (this.ImmComposition != null) - { - this.ImmComposition.OnSelectionChange(); - } + this.TextStore?.OnSelectionChange(); + this.ImmComposition?.OnSelectionChange(); } _IsChanged = value; @@ -226,15 +220,9 @@ bool ITextRange._IsChanged void ITextRange.NotifyChanged(bool disableScroll, bool skipEvents) { // Notify text store about selection movement. - if (this.TextStore != null) - { - this.TextStore.OnSelectionChanged(); - } + this.TextStore?.OnSelectionChanged(); // Notify ImmComposition about selection movement. - if (this.ImmComposition != null) - { - this.ImmComposition.OnSelectionChanged(); - } + this.ImmComposition?.OnSelectionChanged(); if (!skipEvents) { @@ -743,10 +731,7 @@ void ITextSelection.OnTextViewUpdated() // Stress bug#1583327 indicate that _caretElement can be set to null by // detaching. So the below code is caching the caret element instance locally. CaretElement caretElement = _caretElement; - if (caretElement != null) - { - caretElement.OnTextViewUpdated(); - } + caretElement?.OnTextViewUpdated(); } if (_pendingUpdateCaretStateCallback) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesDisplayAttributePropertyRanges.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesDisplayAttributePropertyRanges.cs index 0f33d489085..236564a21a2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesDisplayAttributePropertyRanges.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesDisplayAttributePropertyRanges.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -187,10 +187,7 @@ internal override void OnEndEdit(UnsafeNativeMethods.ITfContext context, // Updates composition display attribute adorner on-screen location. internal void OnLayoutUpdated() { - if (_compositionAdorner != null) - { - _compositionAdorner.InvalidateAdorner(); - } + _compositionAdorner?.InvalidateAdorner(); } #endregion Internal Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesHost.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesHost.cs index 331747a924e..c529ff17fd1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesHost.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesHost.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -158,11 +158,8 @@ internal static void StopTransitoryExtension(TextStore textstore) { UnsafeNativeMethods.ITfSource source; source = textstore.DocumentManager as UnsafeNativeMethods.ITfSource; - if (source != null) - { - // DocumentManager only supports ITfSource on Longhorn, XP does not support it - source.UnadviseSink(textstore.TransitoryExtensionSinkCookie); - } + // DocumentManager only supports ITfSource on Longhorn, XP does not support it + source?.UnadviseSink(textstore.TransitoryExtensionSinkCookie); textstore.TransitoryExtensionSinkCookie = UnsafeNativeMethods.TF_INVALID_COOKIE; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesProperty.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesProperty.cs index 13cc392490a..fac97a479d0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesProperty.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesProperty.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -75,10 +75,7 @@ internal void OnLayoutUpdated() { TextServicesDisplayAttributePropertyRanges displayAttributes = _propertyRanges as TextServicesDisplayAttributePropertyRanges; - if (displayAttributes != null) - { - displayAttributes.OnLayoutUpdated(); - } + displayAttributes?.OnLayoutUpdated(); } #endregion Internal Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs index 0e8e7b0257c..d5277cb188f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -949,11 +949,8 @@ public void GetACPFromPoint(int viewCookie, ref UnsafeNativeMethods.POINT tsfPoi // Convert to local coordinates. GeneralTransform transform = compositionTarget.RootVisual.TransformToDescendant(RenderScope); - if (transform != null) - { - // REVIEW: should we throw if the point could not be transformed? - transform.TryTransform(milPoint, out milPoint); - } + // REVIEW: should we throw if the point could not be transformed? + transform?.TryTransform(milPoint, out milPoint); // Validate layout information on TextView if (!view.Validate(milPoint)) @@ -1696,10 +1693,7 @@ internal void OnLayoutUpdated() } } - if (_textservicesproperty != null) - { - _textservicesproperty.OnLayoutUpdated(); - } + _textservicesproperty?.OnLayoutUpdated(); } // Called as the selection changes. @@ -3353,12 +3347,9 @@ private void BreakTypingSequence(ITextPointer caretPosition) { CompositionParentUndoUnit unit = PeekCompositionParentUndoUnit(); - if (unit != null) - { - // We also put the caret at the end of the composition after - // redoing a composition undo. So update the end position now. - unit.RecordRedoSelectionState(caretPosition, caretPosition); - } + // We also put the caret at the end of the composition after + // redoing a composition undo. So update the end position now. + unit?.RecordRedoSelectionState(caretPosition, caretPosition); } // Repositions an ITextRange to comply with limitations on IME input. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/WinRTSpellerInterop.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/WinRTSpellerInterop.cs index 1804c56c48c..03361a42cdd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/WinRTSpellerInterop.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/WinRTSpellerInterop.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -681,10 +681,7 @@ private void ReleaseAllResources(bool disposing) foreach (Tuple item in _spellCheckers.Values) { SpellChecker spellChecker = item?.Item2; - if (spellChecker != null) - { - spellChecker.Dispose(); - } + spellChecker?.Dispose(); } _spellCheckers = null; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkContentElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkContentElement.cs index e1bc3b3ce63..9b2b90daccd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkContentElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkContentElement.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -282,11 +282,8 @@ public ResourceDictionary Resources ResourceDictionary oldValue = ResourcesField.GetValue(this); ResourcesField.SetValue(this, value); - if (oldValue != null) - { - // This element is no longer an owner for the old RD - oldValue.RemoveOwner(this); - } + // This element is no longer an owner for the old RD + oldValue?.RemoveOwner(this); if (value != null) { @@ -2003,15 +2000,12 @@ internal override void InvalidateForceInheritPropertyOnChildren(DependencyProper while(enumerator.MoveNext()) { DependencyObject child =enumerator.Current as DependencyObject; - if(child != null) - { - // CODE REVIEW (dwaynen) - // - // We assume we will only ever have a UIElement or a ContentElement - // as a child of a FrameworkContentElement. (Not a raw Visual.) + // CODE REVIEW (dwaynen) + // + // We assume we will only ever have a UIElement or a ContentElement + // as a child of a FrameworkContentElement. (Not a raw Visual.) - child.CoerceValue(property); - } + child?.CoerceValue(property); } } } @@ -2039,10 +2033,7 @@ private void EventHandlersStoreAdd(EventPrivateKey key, Delegate handler) private void EventHandlersStoreRemove(EventPrivateKey key, Delegate handler) { EventHandlersStore store = EventHandlersStore; - if (store != null) - { - store.Remove(key, handler); - } + store?.Remove(key, handler); } // Gettor and Settor for flag that indicates diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs index 4298c27703b..98442be888f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -712,13 +712,10 @@ public ResourceDictionary Resources } - if (oldValue != null) - { - // This element is no longer an owner for the old RD - oldValue.RemoveOwner(this); - } + // This element is no longer an owner for the old RD + oldValue?.RemoveOwner(this); - if(this is Window window) + if (this is Window window) { window.AddFluentDictionary(value, out invalidateResources); } @@ -3085,10 +3082,7 @@ internal override void InvalidateForceInheritPropertyOnChildren(DependencyProper while (enumerator.MoveNext()) { DependencyObject child = enumerator.Current as DependencyObject; - if (child != null) - { - child.CoerceValue(property); - } + child?.CoerceValue(property); } } } @@ -5143,7 +5137,7 @@ internal static void InternalSetLayoutTransform(UIElement element, Transform lay FrameworkElement fe = element as FrameworkElement; element.InternalSetOffsetWorkaround(new Vector()); - Transform additionalTransform = (fe == null ? null : fe.GetFlowDirectionTransform()); //rtl + Transform additionalTransform = (fe?.GetFlowDirectionTransform()); //rtl Transform renderTransform = element.RenderTransform; if(renderTransform == Transform.Identity) @@ -5797,10 +5791,7 @@ internal void OnUnloaded(RoutedEventArgs args) internal override void AddSynchronizedInputPreOpportunityHandlerCore(EventRoute route, RoutedEventArgs args) { UIElement uiElement = this._templatedParent as UIElement; - if (uiElement != null) - { - uiElement.AddSynchronizedInputPreOpportunityHandler(route, args); - } + uiElement?.AddSynchronizedInputPreOpportunityHandler(route, args); } @@ -6097,9 +6088,9 @@ internal static void AddIntermediateElementsToRoute( AddStyleHandlersToEventRoute(null, fce, route, args); } } - else if (uiElement3D != null) + else { - uiElement3D.AddToEventRoute(route, args); + uiElement3D?.AddToEventRoute(route, args); } // Get model parent @@ -6132,10 +6123,7 @@ internal void EventHandlersStoreAdd(EventPrivateKey key, Delegate handler) internal void EventHandlersStoreRemove(EventPrivateKey key, Delegate handler) { EventHandlersStore store = EventHandlersStore; - if (store != null) - { - store.Remove(key, handler); - } + store?.Remove(key, handler); } // Gettor and Settor for flag that indicates if this diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs index 4ec233c2e91..dcca848b23e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -103,7 +103,7 @@ public Type Type { knownType = XamlReader.BamlSharedSchemaContext.GetKnownXamlType(_type) as WpfKnownType; } - _knownTypeFactory = (knownType != null) ? knownType.DefaultConstructor : null; + _knownTypeFactory = knownType?.DefaultConstructor; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkTemplate.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkTemplate.cs index 05e38ce055f..df38f2abe10 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkTemplate.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkTemplate.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -418,10 +418,7 @@ public void Seal() //Let go of the TemplateContent object to reduce survived allocations. //Need to keep while parsing due to ambient lookup of DependencyPropertyConverter. - if (_templateHolder != null) - { - _templateHolder.ResetTemplateLoadData(); - } + _templateHolder?.ResetTemplateLoadData(); } // Subclasses need to call this method before any changes to their state. @@ -978,10 +975,7 @@ private void LoadTemplateXaml(System.Xaml.XamlReader templateReader, XamlObjectW while (templateReader.Read()) { - if (lineInfoConsumer != null) - { - lineInfoConsumer.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition); - } + lineInfoConsumer?.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition); // We need to call the ObjectWriter first because x:Name & RNPA needs to be registered // before we call InvalidateProperties. @@ -1044,10 +1038,7 @@ private void LoadTemplateXaml(System.Xaml.XamlReader templateReader, XamlObjectW { if (Names.CurrentFrame.Property == XamlLanguage.ConnectionId) { - if (_styleConnector != null) - { - _styleConnector.Connect((int)templateReader.Value, Names.CurrentFrame.Instance); - } + _styleConnector?.Connect((int)templateReader.Value, Names.CurrentFrame.Instance); } } break; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs index 16ba3ee0c26..a6b9030c8af 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -291,10 +291,7 @@ internal void ChangeLogicalParent(DependencyObject newParent) // to the dispatchers that the elements belong to. // this.VerifyAccess(); - if(newParent != null) - { - newParent.VerifyAccess(); - } + newParent?.VerifyAccess(); // Logical Parent must first be dropped before you are attached to a newParent // This mitigates illegal tree state caused by logical child stealing as illustrated in bug 970706 diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs index 3b682b33bf8..e51f581df27 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -291,10 +291,7 @@ internal void ChangeLogicalParent(DependencyObject newParent) // to the dispatchers that the elements belong to. // this.VerifyAccess(); - if(newParent != null) - { - newParent.VerifyAccess(); - } + newParent?.VerifyAccess(); // Logical Parent must first be dropped before you are attached to a newParent // This mitigates illegal tree state caused by logical child stealing as illustrated in bug 970706 diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs index 01898f6d6c8..f5507ab399d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -800,10 +800,7 @@ internal void HideFocusVisual() if (_focusVisualAdornerCache != null) { AdornerLayer adornerlayer = VisualTreeHelper.GetParent(_focusVisualAdornerCache) as AdornerLayer; - if (adornerlayer != null) - { - adornerlayer.Remove(_focusVisualAdornerCache); - } + adornerlayer?.Remove(_focusVisualAdornerCache); _focusVisualAdornerCache = null; } } @@ -1246,10 +1243,7 @@ internal static void EnableKeyboardCues(DependencyObject element, bool enable) } Visual rootVisual = GetVisualRoot(visual); - if (rootVisual != null) - { - rootVisual.SetValue(ShowKeyboardCuesProperty, enable ? BooleanBoxes.TrueBox : BooleanBoxes.FalseBox); - } + rootVisual?.SetValue(ShowKeyboardCuesProperty, enable ? BooleanBoxes.TrueBox : BooleanBoxes.FalseBox); } internal static FocusNavigationDirection KeyToTraversalDirection(Key key) @@ -2727,8 +2721,7 @@ private DependencyObject GetNextInDirection(DependencyObject sourceElement, else { ContentElement sourceContentElement = sourceElement as ContentElement; - if (sourceContentElement != null) - sourceContentElement.RemoveHandler(Keyboard.PreviewLostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(_LostFocus)); + sourceContentElement?.RemoveHandler(Keyboard.PreviewLostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(_LostFocus)); } UIElement targetUIElement = targetElement as UIElement; @@ -2737,11 +2730,8 @@ private DependencyObject GetNextInDirection(DependencyObject sourceElement, else { ContentElement targetContentElement = targetElement as ContentElement; - if (targetContentElement != null) - { - // When Focus is changed we need to reset the base line - targetContentElement.AddHandler(Keyboard.PreviewLostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(_LostFocus), true); - } + // When Focus is changed we need to reset the base line + targetContentElement?.AddHandler(Keyboard.PreviewLostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(_LostFocus), true); } if (targetUIElement != null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LogicalTreeHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LogicalTreeHelper.cs index 62050354247..15f98abdd58 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LogicalTreeHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/LogicalTreeHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -182,16 +182,10 @@ public static void BringIntoView(DependencyObject current) ArgumentNullException.ThrowIfNull(current); FrameworkElement fe = current as FrameworkElement; - if (fe != null) - { - fe.BringIntoView(); - } + fe?.BringIntoView(); FrameworkContentElement fce = current as FrameworkContentElement; - if (fce != null) - { - fce.BringIntoView(); - } + fce?.BringIntoView(); } /* @@ -368,10 +362,7 @@ internal static void AddLogicalChild(DependencyObject parent, object child) else { FrameworkContentElement parentFCE = parent as FrameworkContentElement; - if (parentFCE != null) - { - parentFCE.AddLogicalChild(child); - } + parentFCE?.AddLogicalChild(child); } } } @@ -384,9 +375,9 @@ internal static void AddLogicalChild(FrameworkElement parentFE, FrameworkContent { parentFE.AddLogicalChild(child); } - else if (parentFCE != null) + else { - parentFCE.AddLogicalChild(child); + parentFCE?.AddLogicalChild(child); } } } @@ -403,10 +394,7 @@ internal static void RemoveLogicalChild(DependencyObject parent, object child) else { FrameworkContentElement parentFCE = parent as FrameworkContentElement; - if (parentFCE != null) - { - parentFCE.RemoveLogicalChild(child); - } + parentFCE?.RemoveLogicalChild(child); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs index 5bf598028fc..32136165512 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -2148,10 +2148,7 @@ private void Process_LinePosition() _context.LineOffset = _binaryReader.ReadInt32(); // We do this cast on every line info, but that is harmless for perf since line info is only in debug build IXamlLineInfoConsumer consumer = _xamlNodesWriter as IXamlLineInfoConsumer; - if (consumer != null) - { - consumer.SetLineInfo(_context.LineNumber, _context.LineOffset); - } + consumer?.SetLineInfo(_context.LineNumber, _context.LineOffset); } // (line, offset) @@ -2161,10 +2158,7 @@ private void Process_LineNumberAndPosition() _context.LineOffset = _binaryReader.ReadInt32(); // We do this cast on every line info, but that is harmless for perf since line info is only in debug build IXamlLineInfoConsumer consumer = _xamlNodesWriter as IXamlLineInfoConsumer; - if (consumer != null) - { - consumer.SetLineInfo(_context.LineNumber, _context.LineOffset); - } + consumer?.SetLineInfo(_context.LineNumber, _context.LineOffset); } private void Process_PIMapping() @@ -2403,10 +2397,7 @@ private void InjectPropertyAndFrameIfNeeded(XamlType elementType, SByte flags) // This is needed to ensure that template root element carries a line info // which can then be used when it is instantiated IXamlLineInfoConsumer consumer = _xamlNodesWriter as IXamlLineInfoConsumer; - if (consumer != null) - { - consumer.SetLineInfo(_context.LineNumber, _context.LineOffset); - } + consumer?.SetLineInfo(_context.LineNumber, _context.LineOffset); } } } @@ -2752,10 +2743,7 @@ bool IFreezeFreezables.TryFreeze(string value, Freezable freezable) Freezable IFreezeFreezables.TryGetFreezable(string value) { Freezable freezable = null; - if (_freezeCache != null) - { - _freezeCache.TryGetValue(value, out freezable); - } + _freezeCache?.TryGetValue(value, out freezable); return freezable; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006ReaderFrame.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006ReaderFrame.cs index 6de85535566..649c1b824c2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006ReaderFrame.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006ReaderFrame.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -86,10 +86,7 @@ public override void Reset() { XamlType = null; Member = null; - if (_namespaces != null) - { - _namespaces.Clear(); - } + _namespaces?.Clear(); Flags = Baml2006ReaderFrameFlags.None; IsDeferredContent = false; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs index 14a6829033d..2f5cb07904d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1752,10 +1752,7 @@ private string EscapeString(string value) } builder.Append('\\'); } - if (builder != null) - { - builder.Append(value[i]); - } + builder?.Append(value[i]); } if (builder == null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordReader.cs index 1a67f73f0b5..745f6b8241e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordReader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -360,10 +360,7 @@ internal BamlRecordType GetNextRecordType() /// internal void Close() { - if (BamlStream != null) - { - BamlStream.Close(); - } + BamlStream?.Close(); EndOfDocument = true; } @@ -2955,10 +2952,7 @@ private void DoRegisterName( string name, object element ) // "myStyle" also gets registered with the Window // "myBrush" gets registered with the Style INameScope nameScopePeek = ParserContext.NameScopeStack.Peek() as INameScope; - if (nameScopePeek != null) - { - nameScopePeek.RegisterName(name, element); - } + nameScopePeek?.RegisterName(name, element); } else { @@ -4427,10 +4421,7 @@ private bool ElementInitialize(object element, string name) } UIElement uiElement = element as UIElement; - if (uiElement != null) - { - uiElement.SetPersistId(++_persistId); - } + uiElement?.SetPersistId(++_persistId); // The second consition is to handle events within standalone dictionaries. // We need to setup the component connector correctly in this case. Note @@ -4869,7 +4860,7 @@ private bool CheckExplicitCollectionTag(ref bool isMarkupExtension) // represent the explicit collection and the grandparent is that property's target. element = GetElementValue(element, GrandParentObjectData, holder.PropertyDefinition.DependencyProperty, ref isMarkupExtension); - elementType = element == null ? null : element.GetType(); + elementType = element?.GetType(); } // the element is an explicit collection if it is assignable to the expected type of the parent or @@ -5341,10 +5332,7 @@ internal void FreezeIfRequired(object element) if (_parserContext.FreezeFreezables) { Freezable f = element as Freezable; - if (f != null) - { - f.Freeze(); - } + f?.Freeze(); } } internal void PreParsedBamlReset() @@ -5497,7 +5485,7 @@ internal object ParentObjectData get { ReaderContextStackData contextData = ParentContext; - return contextData == null ? null : contextData.ObjectData; + return contextData?.ObjectData; } } @@ -5511,7 +5499,7 @@ internal object GrandParentObjectData get { ReaderContextStackData contextData = GrandParentContext; - return contextData == null ? null : contextData.ObjectData; + return contextData?.ObjectData; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordWriter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordWriter.cs index ecfa9fa3884..c3d80cf11e4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordWriter.cs @@ -1627,10 +1627,7 @@ private void WriteDeferableContent(XamlElementEndNode xamlNode) keyRecord = (IBamlDictionaryKey)deferKeyRecord.Record; } Debug.Assert(keyRecord != null, "Unknown key record type in defer load dictionary"); - if (keyRecord != null) - { - keyRecord.UpdateValuePosition((Int32)(position-endOfKeys), BinaryWriter); - } + keyRecord?.UpdateValuePosition((Int32)(position-endOfKeys), BinaryWriter); } WriteBamlRecord(deferRecord.Record, deferRecord.LineNumber, diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/ParserContext.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/ParserContext.cs index c798fcf1a2d..8128c967344 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/ParserContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/ParserContext.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -214,8 +214,7 @@ internal void PushScope() _currentFreezeStackFrame.IncrementRepeatCount(); // Wait till the context needs XmlnsDictionary, create on first use. - if (_xmlnsDictionary != null) - _xmlnsDictionary.PushScope(); + _xmlnsDictionary?.PushScope(); } /// @@ -248,8 +247,7 @@ internal void PopScope() } // Wait till the context needs XmlnsDictionary, create on first use. - if (_xmlnsDictionary != null) - _xmlnsDictionary.PopScope(); + _xmlnsDictionary?.PopScope(); } /// @@ -716,8 +714,8 @@ internal ParserContext Clone() ParserContext context = ScopedCopy(); // Deep copy only selected instance variables - context._mapTable = (_mapTable != null) ? _mapTable.Clone() : null; - context._xamlTypeMapper = (_xamlTypeMapper != null) ? _xamlTypeMapper.Clone() : null; + context._mapTable = _mapTable?.Clone(); + context._xamlTypeMapper = _xamlTypeMapper?.Clone(); // Connect the XamlTypeMapper and bamlmaptable context._xamlTypeMapper.MapTable = context._mapTable; @@ -801,10 +799,7 @@ internal bool TryCacheFreezable(string value, Freezable freezable) internal Freezable TryGetFreezable(string value) { Freezable freezable = null; - if (_freezeCache != null) - { - _freezeCache.TryGetValue(value, out freezable); - } + _freezeCache?.TryGetValue(value, out freezable); return freezable; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs index 91caa0b9c94..20296cc5647 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1223,8 +1223,7 @@ public object Instance public void OnComponentChanged() { - if (_baseContext != null) - _baseContext.OnComponentChanged(); + _baseContext?.OnComponentChanged(); } public bool OnComponentChanging() diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/StyleXamlParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/StyleXamlParser.cs index 1180fbf627d..4f3ab6e73b9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/StyleXamlParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/StyleXamlParser.cs @@ -574,10 +574,7 @@ public override void WriteDefAttribute(XamlDefAttributeNode xamlDefAttributeNode { if (xamlDefAttributeNode.Name == BamlMapTable.NameString) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteDefAttribute(xamlDefAttributeNode); - } + BamlRecordWriter?.WriteDefAttribute(xamlDefAttributeNode); } else { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/TemplateXamlParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/TemplateXamlParser.cs index eebc5cd516c..24addc7c7bc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/TemplateXamlParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/TemplateXamlParser.cs @@ -599,10 +599,7 @@ public override void WriteDefAttribute(XamlDefAttributeNode xamlDefAttributeNode { if (xamlDefAttributeNode.Name == BamlMapTable.NameString) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteDefAttribute(xamlDefAttributeNode); - } + BamlRecordWriter?.WriteDefAttribute(xamlDefAttributeNode); } else { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/WpfXamlLoader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/WpfXamlLoader.cs index c9f39eda86c..fd755ad29ce 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/WpfXamlLoader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/WpfXamlLoader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -98,10 +98,7 @@ private static object Load(System.Xaml.XamlReader xamlReader, IXamlObjectWriterF } UIElement uiElement = args.Instance as UIElement; - if (uiElement != null) - { - uiElement.SetPersistId(persistId++); - } + uiElement?.SetPersistId(persistId++); XamlSourceInfoHelper.SetXamlSourceInfo(args.Instance, args, baseUri); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlParser.cs index 936b0487adb..199fe020ffb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlParser.cs @@ -543,10 +543,7 @@ internal virtual void ProcessXamlNode( /// public virtual void WriteDocumentStart(XamlDocumentStartNode XamlDocumentStartNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteDocumentStart(XamlDocumentStartNode); - } + BamlRecordWriter?.WriteDocumentStart(XamlDocumentStartNode); } /// @@ -554,10 +551,7 @@ public virtual void WriteDocumentStart(XamlDocumentStartNode XamlDocumentStartNo /// public virtual void WriteDocumentEnd(XamlDocumentEndNode xamlEndDocumentNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteDocumentEnd(xamlEndDocumentNode); - } + BamlRecordWriter?.WriteDocumentEnd(xamlEndDocumentNode); } /// @@ -565,10 +559,7 @@ public virtual void WriteDocumentEnd(XamlDocumentEndNode xamlEndDocumentNode) /// public virtual void WriteElementStart(XamlElementStartNode xamlElementStartNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteElementStart(xamlElementStartNode); - } + BamlRecordWriter?.WriteElementStart(xamlElementStartNode); } /// @@ -603,10 +594,7 @@ public virtual void WriteUnknownTagEnd(XamlUnknownTagEndNode xamlUnknownTagEndNo /// public virtual void WriteElementEnd(XamlElementEndNode xamlElementEndNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteElementEnd(xamlElementEndNode); - } + BamlRecordWriter?.WriteElementEnd(xamlElementEndNode); } /// @@ -614,10 +602,7 @@ public virtual void WriteElementEnd(XamlElementEndNode xamlElementEndNode) /// public virtual void WriteLiteralContent(XamlLiteralContentNode xamlLiteralContentNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteLiteralContent(xamlLiteralContentNode); - } + BamlRecordWriter?.WriteLiteralContent(xamlLiteralContentNode); } /// @@ -627,10 +612,7 @@ public virtual void WriteLiteralContent(XamlLiteralContentNode xamlLiteralConten public virtual void WritePropertyComplexStart( XamlPropertyComplexStartNode xamlPropertyComplexStartNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WritePropertyComplexStart(xamlPropertyComplexStartNode); - } + BamlRecordWriter?.WritePropertyComplexStart(xamlPropertyComplexStartNode); } @@ -641,10 +623,7 @@ public virtual void WritePropertyComplexStart( public virtual void WritePropertyComplexEnd( XamlPropertyComplexEndNode xamlPropertyComplexEndNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WritePropertyComplexEnd(xamlPropertyComplexEndNode); - } + BamlRecordWriter?.WritePropertyComplexEnd(xamlPropertyComplexEndNode); } /// @@ -653,10 +632,7 @@ public virtual void WritePropertyComplexEnd( public virtual void WriteKeyElementStart( XamlElementStartNode xamlKeyElementStartNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteKeyElementStart(xamlKeyElementStartNode); - } + BamlRecordWriter?.WriteKeyElementStart(xamlKeyElementStartNode); } /// @@ -665,10 +641,7 @@ public virtual void WriteKeyElementStart( public virtual void WriteKeyElementEnd( XamlElementEndNode xamlKeyElementEndNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteKeyElementEnd(xamlKeyElementEndNode); - } + BamlRecordWriter?.WriteKeyElementEnd(xamlKeyElementEndNode); } /// @@ -697,18 +670,12 @@ public virtual void WriteUnknownAttribute(XamlUnknownAttributeNode xamlUnknownAt /// public virtual void WriteProperty(XamlPropertyNode xamlPropertyNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteProperty(xamlPropertyNode); - } + BamlRecordWriter?.WriteProperty(xamlPropertyNode); } internal void WriteBaseProperty(XamlPropertyNode xamlPropertyNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.BaseWriteProperty(xamlPropertyNode); - } + BamlRecordWriter?.BaseWriteProperty(xamlPropertyNode); } /// @@ -740,10 +707,7 @@ public virtual void WritePropertyWithType(XamlPropertyWithTypeNode xamlPropertyN public virtual void WritePropertyWithExtension(XamlPropertyWithExtensionNode xamlPropertyWithExtensionNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WritePropertyWithExtension(xamlPropertyWithExtensionNode); - } + BamlRecordWriter?.WritePropertyWithExtension(xamlPropertyWithExtensionNode); } @@ -752,10 +716,7 @@ public virtual void WritePropertyWithExtension(XamlPropertyWithExtensionNode xam /// public virtual void WriteText(XamlTextNode xamlTextNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteText(xamlTextNode); - } + BamlRecordWriter?.WriteText(xamlTextNode); } @@ -764,10 +725,7 @@ public virtual void WriteText(XamlTextNode xamlTextNode) /// public virtual void WriteNamespacePrefix(XamlXmlnsPropertyNode xamlXmlnsPropertyNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteNamespacePrefix(xamlXmlnsPropertyNode); - } + BamlRecordWriter?.WriteNamespacePrefix(xamlXmlnsPropertyNode); } @@ -785,10 +743,7 @@ public virtual void WritePIMapping(XamlPIMappingNode xamlPIMappingNode) ThrowException(nameof(SR.ParserMapPIMissingKey), xamlPIMappingNode.LineNumber, xamlPIMappingNode.LinePosition); } - if (BamlRecordWriter != null) - { - BamlRecordWriter.WritePIMapping(xamlPIMappingNode); - } + BamlRecordWriter?.WritePIMapping(xamlPIMappingNode); } /// @@ -806,9 +761,9 @@ public virtual void WriteClrEvent(XamlClrEventNode xamlClrEventNode) xamlClrEventNode.LineNumber, xamlClrEventNode.LinePosition); } - else if (BamlRecordWriter != null) + else { - BamlRecordWriter.WriteClrEvent(xamlClrEventNode); + BamlRecordWriter?.WriteClrEvent(xamlClrEventNode); } } @@ -817,10 +772,7 @@ public virtual void WriteClrEvent(XamlClrEventNode xamlClrEventNode) /// public virtual void WritePropertyArrayStart(XamlPropertyArrayStartNode xamlPropertyArrayStartNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WritePropertyArrayStart(xamlPropertyArrayStartNode); - } + BamlRecordWriter?.WritePropertyArrayStart(xamlPropertyArrayStartNode); } @@ -829,10 +781,7 @@ public virtual void WritePropertyArrayStart(XamlPropertyArrayStartNode xamlPrope /// public virtual void WritePropertyArrayEnd(XamlPropertyArrayEndNode xamlPropertyArrayEndNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WritePropertyArrayEnd(xamlPropertyArrayEndNode); - } + BamlRecordWriter?.WritePropertyArrayEnd(xamlPropertyArrayEndNode); } @@ -841,10 +790,7 @@ public virtual void WritePropertyArrayEnd(XamlPropertyArrayEndNode xamlPropertyA /// public virtual void WritePropertyIListStart(XamlPropertyIListStartNode xamlPropertyIListStartNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WritePropertyIListStart(xamlPropertyIListStartNode); - } + BamlRecordWriter?.WritePropertyIListStart(xamlPropertyIListStartNode); } @@ -853,10 +799,7 @@ public virtual void WritePropertyIListStart(XamlPropertyIListStartNode xamlPrope /// public virtual void WritePropertyIListEnd(XamlPropertyIListEndNode xamlPropertyIListEndNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WritePropertyIListEnd(xamlPropertyIListEndNode); - } + BamlRecordWriter?.WritePropertyIListEnd(xamlPropertyIListEndNode); } /// @@ -864,10 +807,7 @@ public virtual void WritePropertyIListEnd(XamlPropertyIListEndNode xamlPropertyI /// public virtual void WritePropertyIDictionaryStart(XamlPropertyIDictionaryStartNode xamlPropertyIDictionaryStartNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WritePropertyIDictionaryStart(xamlPropertyIDictionaryStartNode); - } + BamlRecordWriter?.WritePropertyIDictionaryStart(xamlPropertyIDictionaryStartNode); } @@ -876,10 +816,7 @@ public virtual void WritePropertyIDictionaryStart(XamlPropertyIDictionaryStartNo /// public virtual void WritePropertyIDictionaryEnd(XamlPropertyIDictionaryEndNode xamlPropertyIDictionaryEndNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WritePropertyIDictionaryEnd(xamlPropertyIDictionaryEndNode); - } + BamlRecordWriter?.WritePropertyIDictionaryEnd(xamlPropertyIDictionaryEndNode); } @@ -890,10 +827,7 @@ public virtual void WritePropertyIDictionaryEnd(XamlPropertyIDictionaryEndNode x /// public virtual void WriteEndAttributes(XamlEndAttributesNode xamlEndAttributesNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteEndAttributes(xamlEndAttributesNode); - } + BamlRecordWriter?.WriteEndAttributes(xamlEndAttributesNode); } /// @@ -915,10 +849,7 @@ public virtual void WriteDefTag(XamlDefTagNode xamlDefTagNode) /// public virtual void WriteDefAttributeKeyType(XamlDefAttributeKeyTypeNode xamlDefNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteDefAttributeKeyType(xamlDefNode); - } + BamlRecordWriter?.WriteDefAttributeKeyType(xamlDefNode); } /// @@ -953,10 +884,7 @@ public virtual void WriteDefAttribute(XamlDefAttributeNode xamlDefAttributeNode) case XamlReaderHelper.DefinitionShared: Boolean.Parse(attributeValue); // For validation only. - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteDefAttribute(xamlDefAttributeNode); - } + BamlRecordWriter?.WriteDefAttribute(xamlDefAttributeNode); break; case XamlReaderHelper.DefinitionUid: @@ -976,17 +904,11 @@ public virtual void WriteDefAttribute(XamlDefAttributeNode xamlDefAttributeNode) throw parseException; } - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteDefAttribute(xamlDefAttributeNode); - } + BamlRecordWriter?.WriteDefAttribute(xamlDefAttributeNode); break; case XamlReaderHelper.DefinitionName: - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteDefAttribute(xamlDefAttributeNode); - } + BamlRecordWriter?.WriteDefAttribute(xamlDefAttributeNode); break; default: @@ -1005,10 +927,7 @@ public virtual void WriteDefAttribute(XamlDefAttributeNode xamlDefAttributeNode) /// public virtual void WritePresentationOptionsAttribute(XamlPresentationOptionsAttributeNode xamlPresentationOptionsAttributeNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WritePresentationOptionsAttribute(xamlPresentationOptionsAttributeNode); - } + BamlRecordWriter?.WritePresentationOptionsAttribute(xamlPresentationOptionsAttributeNode); } /// @@ -1016,18 +935,12 @@ public virtual void WritePresentationOptionsAttribute(XamlPresentationOptionsAtt /// public virtual void WriteConstructorParametersStart(XamlConstructorParametersStartNode xamlConstructorParametersStartNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteConstructorParametersStart(xamlConstructorParametersStartNode); - } + BamlRecordWriter?.WriteConstructorParametersStart(xamlConstructorParametersStartNode); } public virtual void WriteContentProperty(XamlContentPropertyNode xamlContentPropertyNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteContentProperty(xamlContentPropertyNode); - } + BamlRecordWriter?.WriteContentProperty(xamlContentPropertyNode); } /// @@ -1037,10 +950,7 @@ public virtual void WriteContentProperty(XamlContentPropertyNode xamlContentProp public virtual void WriteConstructorParameterType( XamlConstructorParameterTypeNode xamlConstructorParameterTypeNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteConstructorParameterType(xamlConstructorParameterTypeNode); - } + BamlRecordWriter?.WriteConstructorParameterType(xamlConstructorParameterTypeNode); } /// @@ -1048,10 +958,7 @@ public virtual void WriteConstructorParameterType( /// public virtual void WriteConstructorParametersEnd(XamlConstructorParametersEndNode xamlConstructorParametersEndNode) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteConstructorParametersEnd(xamlConstructorParametersEndNode); - } + BamlRecordWriter?.WriteConstructorParametersEnd(xamlConstructorParametersEndNode); } /// @@ -1110,10 +1017,7 @@ public virtual bool GetElementType( /// protected internal void WriteConnectionId(Int32 connectionId) { - if (BamlRecordWriter != null) - { - BamlRecordWriter.WriteConnectionId(connectionId); - } + BamlRecordWriter?.WriteConnectionId(connectionId); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReader.cs index 89757eea51b..76ae2b8d6c4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -362,10 +362,7 @@ private object LoadAsync(XmlReader reader, ParserContext parserContext, bool use } UIElement uiElement = args.Instance as UIElement; - if (uiElement != null) - { - uiElement.SetPersistId(_persistId++); - } + uiElement?.SetPersistId(_persistId++); DependencyObject dObject = args.Instance as DependencyObject; if (dObject != null && _stack.CurrentFrame.XmlnsDictionary != null) @@ -967,7 +964,7 @@ public static object Load(System.Xaml.XamlReader reader) catch (Exception e) { IUriContext uriContext = reader as IUriContext; - Uri baseUri = (uriContext != null) ? uriContext.BaseUri : null; + Uri baseUri = uriContext?.BaseUri; // Don't wrap critical exceptions or already-wrapped exceptions. if (MS.Internal.CriticalExceptions.IsCriticalException(e) || !ShouldReWrapException(e, baseUri)) { @@ -1087,10 +1084,7 @@ internal static object LoadBaml( } DependencyObject dObject = root as DependencyObject; - if (dObject != null) - { - dObject.SetValue(BaseUriHelper.BaseUriProperty, readerSettings.BaseUri); - } + dObject?.SetValue(BaseUriHelper.BaseUriProperty, readerSettings.BaseUri); Application app = root as Application; if (app != null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs index 9348fae75f1..2347b7b39f0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs @@ -3703,7 +3703,7 @@ private void CompileBamlTag( Debug.Assert(typeAndSerializer == null || typeAndSerializer.SerializerType == null || propertyType == typeAndSerializer.ObjectType); - serializerType = typeAndSerializer != null ? typeAndSerializer.SerializerType : null; + serializerType = typeAndSerializer?.SerializerType; CompileComplexProperty(dynamicObject, propertyType, serializerType, depth, assemblyName, typeFullName, dynamicObjectName, diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs index 3b46b06a617..71744c2705b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -119,7 +119,7 @@ public Type GetType( TypeAndSerializer typeAndSerializer = GetTypeOnly(xmlNamespace,localName); - return typeAndSerializer != null ? typeAndSerializer.ObjectType : null; + return typeAndSerializer?.ObjectType; } #if !PBTCOMPILER @@ -168,10 +168,7 @@ public void AddMappingProcessingInstruction( _piReverseTable[fullName] = xmlNamespace; // Add mapping to the SchemaContext - if (_schemaContext != null) - { - _schemaContext.SetMappingProcessingInstruction(xmlNamespace, pair); - } + _schemaContext?.SetMappingProcessingInstruction(xmlNamespace, pair); } #endif /// @@ -1408,17 +1405,7 @@ private MemberInfo GetClrInfoForClass( if (null != memberInfo) { - if (infoRecord != null) - { -#if !PBTCOMPILER - // DP's aren't present in the PBT case - if (infoRecord.DP == null) - { - infoRecord.DP = MapTable.GetDependencyProperty(infoRecord); - } -#endif - infoRecord.SetPropertyMember(memberInfo); - } + infoRecord?.SetPropertyMember(memberInfo); } } } @@ -1552,17 +1539,7 @@ private MemberInfo GetClrInfoForClass( if (null != memberInfo) { - if (infoRecord != null) - { -#if !PBTCOMPILER - // DP's aren't present in the PBT case - if (infoRecord.DP == null) - { - infoRecord.DP = MapTable.GetDependencyProperty(infoRecord); - } -#endif - infoRecord.SetPropertyMember(memberInfo); - } + infoRecord?.SetPropertyMember(memberInfo); } } } @@ -2177,7 +2154,7 @@ internal static Type GetTypeFromName(string typeName, DependencyObject element) XmlnsDictionary prefixDictionary = element.GetValue(XmlAttributeProperties.XmlnsDictionaryProperty) as XmlnsDictionary; - object xmlNamespaceObject = (prefixDictionary != null) ? prefixDictionary[prefix] : null; + object xmlNamespaceObject = prefixDictionary?[prefix]; // Then get the list of NamespaceMapEntry objects that maps the xml namespace uri to one // or more clr namespace / assembly pairs. This should be stored on the root element diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsDictionary.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsDictionary.cs index cb686bb766b..9e3dfaa8f90 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsDictionary.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsDictionary.cs @@ -256,8 +256,7 @@ IEnumerator IEnumerable.GetEnumerator() public void CopyTo(Array array, int index) { IDictionary dict = GetNamespacesInScope(NamespaceScope.All) as IDictionary; - if (dict != null) - dict.CopyTo(array,index); + dict?.CopyTo(array,index); } #endregion ICollectionMethods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs index ab70e42c175..9f8f7d9e202 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1585,10 +1585,7 @@ private void PauseImpl(DependencyObject containingObject) { Clock clock = GetStoryboardClock(containingObject, false, InteractiveOperation.Pause); - if (clock != null) - { - clock.Controller.Pause(); - } + clock?.Controller.Pause(); if( TraceAnimation.IsEnabled ) { @@ -1632,10 +1629,7 @@ private void RemoveImpl(DependencyObject containingObject) { clock.Controller.Remove(); HybridDictionary clocks = StoryboardClockTreesField.GetValue(containingObject); - if (clocks != null) - { - clocks.Remove(this); - } + clocks?.Remove(this); } if( TraceAnimation.IsEnabled ) @@ -1679,10 +1673,7 @@ private void ResumeImpl( DependencyObject containingObject ) { Clock clock = GetStoryboardClock(containingObject, false, InteractiveOperation.Resume); - if (clock != null) - { - clock.Controller.Resume(); - } + clock?.Controller.Resume(); if( TraceAnimation.IsEnabled ) { @@ -1738,12 +1729,9 @@ private void SeekImpl( DependencyObject containingObject, TimeSpan offset, TimeS { Clock clock = GetStoryboardClock(containingObject, false, InteractiveOperation.Seek); - if (clock != null) - { // Seek is a public API as well, so its parameters should get validated there. - clock.Controller.Seek(offset, origin); + clock?.Controller.Seek(offset, origin); } - } /// /// Given an object, look on the clock store for a clock that was @@ -1789,12 +1777,9 @@ private void SeekAlignedToLastTickImpl( DependencyObject containingObject, TimeS { Clock clock = GetStoryboardClock(containingObject, false, InteractiveOperation.SeekAlignedToLastTick); - if (clock != null) - { // SeekAlignedToLastTick is a public API as well, so its parameters should get validated there. - clock.Controller.SeekAlignedToLastTick(offset, origin); + clock?.Controller.SeekAlignedToLastTick(offset, origin); } - } /// /// Given an object, look on the clock store for a clock that was @@ -1867,10 +1852,7 @@ private void SkipToFillImpl( DependencyObject containingObject ) { Clock clock = GetStoryboardClock(containingObject, false, InteractiveOperation.SkipToFill); - if (clock != null) - { - clock.Controller.SkipToFill(); - } + clock?.Controller.SkipToFill(); } /// @@ -1904,10 +1886,7 @@ private void StopImpl( DependencyObject containingObject ) { Clock clock = GetStoryboardClock(containingObject, false, InteractiveOperation.Stop); - if (clock != null) - { - clock.Controller.Stop(); - } + clock?.Controller.Stop(); if( TraceAnimation.IsEnabled ) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/Journal.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/Journal.cs index 41803f2a1a4..77dc84f0f0e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/Journal.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/Journal.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -468,15 +468,9 @@ internal void PruneKeepAliveEntries() Debug.Assert(je.GetType().IsSerializable); // There can be keep-alive JEs creates for child frames. DataStreams jds = je.JEGroupState.JournalDataStreams; - if (jds != null) - { - jds.PrepareForSerialization(); - } + jds?.PrepareForSerialization(); - if (je.RootViewerState != null) - { - je.RootViewerState.PrepareForSerialization(); - } + je.RootViewerState?.PrepareForSerialization(); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationService.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationService.cs index 4196face476..a89448467c0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationService.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationService.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -397,10 +397,7 @@ private static void BringIntoView(DependencyObject elem) else { FrameworkContentElement fce = elem as FrameworkContentElement; - if (fce != null) - { - fce.BringIntoView(); - } + fce?.BringIntoView(); } } @@ -452,10 +449,7 @@ private bool RestoreRootViewerState(CustomJournalStateInternal rvs) if (v == null) return false; // Template may not be applied yet. IJournalState ijs = v as IJournalState; - if (ijs != null) - { - ijs.RestoreJournalState(rvs); - } + ijs?.RestoreJournalState(rvs); //else: maybe type of viewer changed. Still returning true so that restoring state // is not reattempted in this case. return true; @@ -576,11 +570,8 @@ internal void OnParentNavigationServiceChanged() if (newParent == oldParent) return; - if (oldParent != null) - { - // Remove from old parent's list - oldParent.RemoveChild(this); - } + // Remove from old parent's list + oldParent?.RemoveChild(this); if (newParent != null) { @@ -603,11 +594,8 @@ internal void AddChild(NavigationService ncChild) ChildNavigationServices.Add(ncChild); ncChild._parentNavigationService = this; - if (JournalScope != null) - { - // The view may need to be changed if NavigationContainers came or went - JournalScope.Journal.UpdateView(); - } + // The view may need to be changed if NavigationContainers came or went + JournalScope?.Journal.UpdateView(); // If parent's navigation was stopped, stop pending navigations in the child as well if (this.NavStatus == NavigationStatus.Stopped) @@ -636,11 +624,8 @@ internal void RemoveChild(NavigationService ncChild) ncChild.InvalidateJournalNavigationScope(); } - if (JournalScope != null) - { - // The view may need to be changed if NavigationContainers came or went - JournalScope.Journal.UpdateView(); - } + // The view may need to be changed if NavigationContainers came or went + JournalScope?.Journal.UpdateView(); // Do we need to stop navigations in the child? // If no, then just remove from our PendingNavigationList @@ -888,7 +873,7 @@ private bool HookupNewTree(Object newTree, NavigateInfo navInfo, Uri newUri) // This will be non-null IFF a PageFunction with a non-PageFunction parent has finished. // Then navInfo.NavigationMode may be Back or New. // (New iff finishingChildPageFunction.RemoveFromJournal==false). - PageFunctionBase finishingChildPageFunction = (pfReturnInfo != null) ? pfReturnInfo.FinishingChildPageFunction : null; + PageFunctionBase finishingChildPageFunction = pfReturnInfo?.FinishingChildPageFunction; Debug.Assert(finishingChildPageFunction == null || !IsPageFunction(newTree) && (finishingChildPageFunction.RemoveFromJournal && navInfo.NavigationMode == NavigationMode.Back || @@ -899,7 +884,7 @@ private bool HookupNewTree(Object newTree, NavigateInfo navInfo, Uri newUri) // has just finished if (finishingChildPageFunction != null) { - object returnEventArgs = (pfReturnInfo != null) ? pfReturnInfo.ReturnEventArgs : null; + object returnEventArgs = pfReturnInfo?.ReturnEventArgs; if (newTree != null) { @@ -910,10 +895,7 @@ private bool HookupNewTree(Object newTree, NavigateInfo navInfo, Uri newUri) // Return event handler should not be left attached. Debug.Assert(finishingChildPageFunction._Return == null); - if (pfReturnInfo.JournalEntry != null) - { - pfReturnInfo.JournalEntry.SaveState(newTree); - } + pfReturnInfo.JournalEntry?.SaveState(newTree); return false; } } @@ -1074,25 +1056,19 @@ internal void VisualTreeAvailable(Visual v) { if (!ReferenceEquals(v, _oldRootVisual)) { - if (_oldRootVisual != null) - { - // Step 1: Remove the inherited NavigationService property - // This will cause a property invalidation and sub-frames will remove themselves from the parent's list - // That will cause a Journal view update so back/fwd state reflects the state of the new tree - _oldRootVisual.SetValue(NavigationServiceProperty, null); - } + // Step 1: Remove the inherited NavigationService property + // This will cause a property invalidation and sub-frames will remove themselves from the parent's list + // That will cause a Journal view update so back/fwd state reflects the state of the new tree + _oldRootVisual?.SetValue(NavigationServiceProperty, null); - if (v != null) - { - // Step 1: Set the inherited NavigationService property - // This will cause a property invalidation and sub-frames will remove themselves from the parent's list - // That will cause a Journal view update so back/fwd state reflects the state of the new tree - // Note: setting NavigationService has a non-obvious side effect - - // if v has any data-bound properties that use ElementName binding, - // the name will be resolved in the "inner scope", not the "outer - // scope". (Bug 1765041) - v.SetValue(NavigationServiceProperty, this); - } + // Step 1: Set the inherited NavigationService property + // This will cause a property invalidation and sub-frames will remove themselves from the parent's list + // That will cause a Journal view update so back/fwd state reflects the state of the new tree + // Note: setting NavigationService has a non-obvious side effect - + // if v has any data-bound properties that use ElementName binding, + // the name will be resolved in the "inner scope", not the "outer + // scope". (Bug 1765041) + v?.SetValue(NavigationServiceProperty, this); _oldRootVisual = v; } @@ -1138,7 +1114,7 @@ void IContentContainer.OnContentReady(ContentType contentType, Object bp, Uri bp "Source in OnContentReady does not match source in NavigateInfo"); if (bpu == null) { - bpu = (navInfo == null) ? null : navInfo.Source; + bpu = navInfo?.Source; } Uri bpuClean = BindUriHelper.GetUriRelativeToPackAppBase(bpu); @@ -1659,7 +1635,7 @@ public bool Navigate(Object root, Object navigationState) throw new InvalidOperationException(SR.InvalidOperation_CannotReenterPageFunction); } - Uri source = navigateInfo == null ? null : navigateInfo.Source; + Uri source = navigateInfo?.Source; // HandleNavigating will set the pending Uri from navigationState if available // See comments in NavigateInfo class @@ -1886,10 +1862,7 @@ private void DoStopLoading(bool clearRecursiveNavigations, bool fireEvents) fireStopped = true; } - if (_navigatorHostImpl != null) - { - _navigatorHostImpl.OnSourceUpdatedFromNavService(true /* journalOrCancel */); - } + _navigatorHostImpl?.OnSourceUpdatedFromNavService(true /* journalOrCancel */); // Event handler exception continuality: if exception occurs in NavigationStopped event handler, // we want to finish stopping navigation. @@ -2085,10 +2058,7 @@ private bool FireNavigating(Uri source, Object bp, Object navState, WebRequest r if (e.Cancel) { - if (JournalScope != null) - { - JournalScope.AbortJournalNavigation(); - } + JournalScope?.AbortJournalNavigation(); } return (!e.Cancel && !IsDisposed); @@ -2179,10 +2149,7 @@ private bool HandleNavigating(Uri source, Object content, Object navState, WebRe private void CleanupAfterNavigationCancelled(NavigateQueueItem localNavigateQueueItem) { - if (JournalScope != null) - { - JournalScope.AbortJournalNavigation(); - } + JournalScope?.AbortJournalNavigation(); // If event was canceled then we need to remove it. // If the event was canceled AND superceded by StopLoading or Navigate, it won't be @@ -2191,10 +2158,7 @@ private void CleanupAfterNavigationCancelled(NavigateQueueItem localNavigateQueu // and the caller could now proceed with the navigation _recursiveNavigateList.Remove(localNavigateQueueItem); - if (_navigatorHostImpl != null) - { - _navigatorHostImpl.OnSourceUpdatedFromNavService(true /* journalOrCancel */); - } + _navigatorHostImpl?.OnSourceUpdatedFromNavService(true /* journalOrCancel */); // Browser downloading state not reset; case 4. InformBrowserAboutStoppedNavigation(); @@ -3076,7 +3040,7 @@ internal void DoNavigate(Object bp, NavigationMode navFlags, Object navState) Invariant.Assert(navFlags != NavigationMode.Refresh ^ object.ReferenceEquals(bp, _bp), "Navigating to the same object should be handled as fragment navigation, except for Refresh."); - Uri source = navigateInfo == null ? null : navigateInfo.Source; + Uri source = navigateInfo?.Source; // The baseUri passed to GetResolvedUri() is null because here we have a new Content // object. Its URI is not resolved relative to the URI of the previous Content. Uri resolvedSource = BindUriHelper.GetResolvedUri(null, source); @@ -3526,10 +3490,7 @@ internal INavigator INavigatorHost if (_navigatorHost != null) { IInputElement iie = _navigatorHost as IInputElement; - if (iie != null) - { - iie.RemoveHandler(Hyperlink.RequestNavigateEvent, navHandler); - } + iie?.RemoveHandler(Hyperlink.RequestNavigateEvent, navHandler); IDownloader oldDownloader = _navigatorHost as IDownloader; if (oldDownloader != null) @@ -3541,10 +3502,7 @@ internal INavigator INavigatorHost if (value != null) { IInputElement iie = value as IInputElement; - if (iie != null) - { - iie.AddHandler(Hyperlink.RequestNavigateEvent, navHandler); - } + iie?.AddHandler(Hyperlink.RequestNavigateEvent, navHandler); // We want to listen to ContentRendered of the INavigatorHost so // that we can scroll into view the correct element if needed @@ -4509,10 +4467,7 @@ internal void DisposeElement(Object node) // Now that we've recursed through all descendants, dispose this node if it needs it IDisposable disposable = node as IDisposable; - if (disposable != null) - { - disposable.Dispose(); - } + disposable?.Dispose(); } internal DisposeTreeQueueItem(Object node) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationWindow.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationWindow.cs index 68f2e691d0d..570171cb0ea 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationWindow.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationWindow.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -419,10 +419,7 @@ public override void OnApplyTemplate() // Get the root element of the style FrameworkElement root = (this.GetVisualChild(0)) as FrameworkElement; - if (_navigationService != null) - { - _navigationService.VisualTreeAvailable(root); - } + _navigationService?.VisualTreeAvailable(root); // did we just apply the framelet style? if ((root != null) && (root.Name == "NavigationBarRoot")) @@ -623,7 +620,7 @@ public Uri CurrentSource get { VerifyContextAndObjectState( ); - return (_navigationService == null ? null : _navigationService.CurrentSource); + return (_navigationService?.CurrentSource); } } @@ -867,8 +864,7 @@ protected override void OnClosed(EventArgs args) base.OnClosed( args ) ; // detach the event handlers on the NC - if(_navigationService != null) - _navigationService.Dispose(); + _navigationService?.Dispose(); } #endregion Protected Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs index 2a464e263de..95b27661cc7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -859,7 +859,7 @@ Type GetTypeFromName(string name, object context) TypeAndSerializer typeAndSerializer = parserContext.XamlTypeMapper.GetTypeOnly(namespaceURI, name); - return (typeAndSerializer != null) ? typeAndSerializer.ObjectType : null; + return typeAndSerializer?.ObjectType; } else diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceDictionary.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceDictionary.cs index b22e28f6662..c4ebfe04000 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceDictionary.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceDictionary.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1826,13 +1826,10 @@ private void ValidateDeferredResourceReferences(object resourceKey) void Inflate(DeferredResourceReference deferredResourceReference) { - if (deferredResourceReference is not null) - { - // This will inflate the deferred reference, causing it - // to be removed from the list. The list may also be - // purged of dead references. - deferredResourceReference.GetValue(BaseValueSourceInternal.Unknown); - } + // This will inflate the deferred reference, causing it + // to be removed from the list. The list may also be + // purged of dead references. + deferredResourceReference?.GetValue(BaseValueSourceInternal.Unknown); } } } @@ -2543,10 +2540,7 @@ private void MoveDeferredResourceReferencesFrom(ResourceDictionary loadedRD) _deferredResourceReferencesList = loadedRD._deferredResourceReferencesList; // redirect each entry toward its new owner - if (_deferredResourceReferencesList != null) - { - _deferredResourceReferencesList.ChangeDictionary(this); - } + _deferredResourceReferencesList?.ChangeDictionary(this); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs index 3822e12022a..a5b1f69a001 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -233,11 +233,8 @@ public static void SetJumpList(Application application, JumpList value) } } - if (value != null) - { - // Changes will only get applied if the list isn't in an ISupportInitialize block. - value.ApplyFromApplication(); - } + // Changes will only get applied if the list isn't in an ISupportInitialize block. + value?.ApplyFromApplication(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs index 33eb9da1b09..46dd7a27b64 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -514,26 +514,17 @@ public void Seal() } // Seal setters - if (_setters != null) - { - _setters.Seal(); - } + _setters?.Seal(); // Seal triggers - if (_visualTriggers != null) - { - _visualTriggers.Seal(); - } + _visualTriggers?.Seal(); // Will throw InvalidOperationException if we find a loop of // BasedOn references. (A.BasedOn = B, B.BasedOn = C, C.BasedOn = A) CheckForCircularBasedOnReferences(); // Seal BasedOn Style chain - if (_basedOn != null) - { - _basedOn.Seal(); - } + _basedOn?.Seal(); // Seal the ResourceDictionary if (_resources != null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs index fb2d6049ba6..179af068fe9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -363,10 +363,7 @@ internal static void SealTemplate( // Seal template nodes (if exists) - if (frameworkTemplate != null) - { - frameworkTemplate.ProcessTemplateBeforeSeal(); - } + frameworkTemplate?.ProcessTemplateBeforeSeal(); if (templateRoot != null) @@ -381,10 +378,7 @@ internal static void SealTemplate( } // Seal triggers - if (triggers != null) - { - triggers.Seal(); - } + triggers?.Seal(); // Seal Resource Dictionary if (resources != null) @@ -1441,7 +1435,7 @@ internal static void ReleaseInstanceData( if (oldStyle != null) { - HybridDictionary instanceValues = (styleData != null) ? styleData[(int)InstanceStyleData.InstanceValues] : null; + HybridDictionary instanceValues = styleData?[(int)InstanceStyleData.InstanceValues]; ReleaseInstanceDataForDataTriggers(dataField, instanceValues, oldStyle, oldFrameworkTemplate ); if (oldStyle.HasInstanceValues) { @@ -1452,7 +1446,7 @@ internal static void ReleaseInstanceData( } else if (oldFrameworkTemplate != null) { - HybridDictionary instanceValues = (styleData != null) ? styleData[(int)InstanceStyleData.InstanceValues] : null; + HybridDictionary instanceValues = styleData?[(int)InstanceStyleData.InstanceValues]; ReleaseInstanceDataForDataTriggers(dataField, instanceValues, oldStyle, oldFrameworkTemplate ); if (oldFrameworkTemplate.HasInstanceValues) { @@ -1463,7 +1457,7 @@ internal static void ReleaseInstanceData( } else { - HybridDictionary instanceValues = (styleData != null) ? styleData[(int)InstanceStyleData.InstanceValues] : null; + HybridDictionary instanceValues = styleData?[(int)InstanceStyleData.InstanceValues]; ReleaseInstanceDataForDataTriggers(dataField, instanceValues, oldStyle, oldFrameworkTemplate ); } } @@ -2162,10 +2156,7 @@ internal static void ClearGeneratedSubTree( } // Clear the NameMap property on the root of the generated subtree - if (rootNode != null) - { - rootNode.ClearValue(NameScope.NameScopeProperty); - } + rootNode?.ClearValue(NameScope.NameScopeProperty); // Detach the generated tree from the conatiner DetachGeneratedSubTree(feContainer, fceContainer); @@ -2219,7 +2210,7 @@ private static void ClearTemplateChain( FrameworkObject container = new FrameworkObject(feContainer, fceContainer); - HybridDictionary instanceValues = (instanceData != null) ? instanceData[(int)InstanceStyleData.InstanceValues] : null; + HybridDictionary instanceValues = instanceData?[(int)InstanceStyleData.InstanceValues]; int[] childIndices = new int[templateChain.Count]; // Assumes that styleChain[0] is the root of the templated subtree @@ -2915,11 +2906,11 @@ internal static object GetInstanceValue( FrameworkContentElement fceContainer; Helper.DowncastToFEorFCE(container, out feContainer, out fceContainer, true); - HybridDictionary[] styleData = (dataField != null) ? dataField.GetValue(container) : null; - HybridDictionary instanceValues = (styleData != null) ? styleData[(int)InstanceStyleData.InstanceValues] : null; + HybridDictionary[] styleData = dataField?.GetValue(container); + HybridDictionary instanceValues = styleData?[(int)InstanceStyleData.InstanceValues]; InstanceValueKey key = new InstanceValueKey(childIndex, dp.GlobalIndex, i); - object value = (instanceValues != null)? instanceValues[key] : null; + object value = instanceValues?[key]; bool isRequestingExpression = (feChild != null) ? feChild.IsRequestingExpression : fceChild.IsRequestingExpression; if (value == null) @@ -2976,10 +2967,7 @@ internal static object GetInstanceValue( { expr = value as Expression; // if the instance value is an expression, attach it - if (expr != null) - { - expr.OnAttach(child, dp); - } + expr?.OnAttach(child, dp); } } @@ -3377,8 +3365,8 @@ internal static void DoTemplateInvalidations( FrugalStructList newContainerDependents; Debug.Assert(feContainer != null); - oldFactory = (oldFrameworkTemplate != null) ? oldFrameworkTemplate.VisualTree : null; - newFactory = (newFrameworkTemplate != null) ? newFrameworkTemplate.VisualTree : null; + oldFactory = oldFrameworkTemplate?.VisualTree; + newFactory = newFrameworkTemplate?.VisualTree; canBuildVisualTree = (oldFrameworkTemplate != null) ? oldFrameworkTemplate.CanBuildVisualTree : false; hasTemplateGeneratedSubTree = feContainer.HasTemplateGeneratedSubTree; @@ -5512,8 +5500,8 @@ internal static Expression GetExpression( { if (fe != null) fe.WriteInternalFlag(InternalFlags.IsInitialized, true); - else if (fce != null) - fce.WriteInternalFlag(InternalFlags.IsInitialized, true); + else + fce?.WriteInternalFlag(InternalFlags.IsInitialized, true); } // get the desired expression @@ -5524,8 +5512,8 @@ internal static Expression GetExpression( { if (fe != null) fe.WriteInternalFlag(InternalFlags.IsInitialized, false); - else if (fce != null) - fce.WriteInternalFlag(InternalFlags.IsInitialized, false); + else + fce?.WriteInternalFlag(InternalFlags.IsInitialized, false); } return result; @@ -5886,7 +5874,7 @@ internal bool ConvertAndMatch(object state) // compare the state and reference values directly.) object referenceValue = Value; string referenceString = referenceValue as String; - Type stateType = (state != null) ? state.GetType() : null; + Type stateType = state?.GetType(); if (referenceString != null && stateType != null && stateType != typeof(String)) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs index 1746f86fc5c..87e3ba71c29 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -310,11 +310,8 @@ private static bool FindCachedResource(object key, ref object resource, bool mus else { DispatcherObject dispatcherObject = resource as DispatcherObject; - if (dispatcherObject != null) - { - // The current thread may not have access to this object. - dispatcherObject.VerifyAccess(); - } + // The current thread may not have access to this object. + dispatcherObject?.VerifyAccess(); } if (found && mustReturnDeferredResourceReference) @@ -1801,7 +1798,7 @@ internal override Type GetValueType() } else { - return _keyOrValue != null ? _keyOrValue.GetType() : null; + return _keyOrValue?.GetType(); } } @@ -1835,10 +1832,7 @@ internal virtual void RemoveInflatedListener(ResourceReferenceExpression listene { Debug.Assert(_inflatedList != null); - if (_inflatedList != null) - { - _inflatedList.Remove(listener); - } + _inflatedList?.Remove(listener); } #endregion Methods @@ -2021,7 +2015,7 @@ internal override object GetValue(BaseValueSourceInternal valueSource) internal override Type GetValueType() { object value = Value; - return value != null ? value.GetType() : null; + return value?.GetType(); } #endregion Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContent.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContent.cs index a161353245c..ba37b8bed03 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContent.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContent.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -370,10 +370,7 @@ private void ParseNodes( while (reader.Read()) { - if (lineInfoConsumer != null) - { - lineInfoConsumer.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition); - } + lineInfoConsumer?.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition); object newValue; bool reProcessOnApply = ParseNode(reader, stack, sharedProperties, ref nameNumber, out newValue); @@ -984,10 +981,7 @@ private bool TrySharingProperty(System.Xaml.XamlReader xamlReader, // events inside of a FramewokrTemplate if (!insideTemplate && frames.CurrentFrame.Property == XamlLanguage.ConnectionId) { - if (OwnerTemplate.StyleConnector != null) - { - OwnerTemplate.StyleConnector.Connect((int)xamlReader.Value, frames.CurrentFrame.Instance); - } + OwnerTemplate.StyleConnector?.Connect((int)xamlReader.Value, frames.CurrentFrame.Instance); } break; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs index 14ac293fdc0..60e1c91a14a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -553,10 +553,7 @@ internal static void OnResourcesChanged( if (info.IsImplicitDataTemplateChange) { ContentPresenter contentPresenter = fe as ContentPresenter; - if (contentPresenter != null) - { - contentPresenter.ReevaluateTemplate(); - } + contentPresenter?.ReevaluateTemplate(); } if (fe.HasResourceReference) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs index b0d497d134b..504bf660761 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -248,14 +248,8 @@ internal override void Seal() } } - if( _enterActions != null ) - { - _enterActions.Seal(this); - } - if( _exitActions != null ) - { - _exitActions.Seal(this); - } + _enterActions?.Seal(this); + _exitActions?.Seal(this); // Remove thread affinity so it can be accessed across threads DetachFromDispatcher(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/VisualStateManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/VisualStateManager.cs index 0c3017b7d2e..b46a89d943b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/VisualStateManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/VisualStateManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -374,7 +374,7 @@ private static Storyboard GenerateDynamicTransitionAnimations(FrameworkElement r } Dictionary currentAnimations = FlattenTimelines(group.CurrentStoryboards); - Dictionary transitionAnimations = FlattenTimelines(transition != null ? transition.Storyboard : null); + Dictionary transitionAnimations = FlattenTimelines(transition?.Storyboard); Dictionary newStateAnimations = FlattenTimelines(newState.Storyboard); // Remove any animations that the transition already animates. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs index ad3c6198892..b942c1825f2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1280,12 +1280,9 @@ public Window Owner } // Update OwnerWindows of the previous owner - if (_ownerWindow != null) - { - // using OwnedWindowsInternl b/c we want to modifying the - // underlying collection - _ownerWindow.OwnedWindowsInternal.Remove(this); - } + // using OwnedWindowsInternl b/c we want to modifying the + // underlying collection + _ownerWindow?.OwnedWindowsInternal.Remove(this); } // Update parent handle. If value is null, then make parent @@ -1304,12 +1301,9 @@ public Window Owner SetOwnerHandle(_ownerWindow != null ? _ownerWindow.CriticalHandle: IntPtr.Zero); // Update OwnerWindows of the new owner - if (_ownerWindow != null) - { - // using OwnedWindowsInternl b/c we want to modifying the - // underlying collection - _ownerWindow.OwnedWindowsInternal.Add(this); - } + // using OwnedWindowsInternl b/c we want to modifying the + // underlying collection + _ownerWindow?.OwnedWindowsInternal.Add(this); } } @@ -2092,8 +2086,7 @@ protected virtual void OnContentRendered(EventArgs e) if (doContent != null) { IInputElement focusedElement = FocusManager.GetFocusedElement(doContent) as IInputElement; - if (focusedElement != null) - focusedElement.Focus(); + focusedElement?.Focus(); } EventHandler handler = (EventHandler)Events[EVENT_CONTENTRENDERED]; @@ -3540,12 +3533,9 @@ private void PostContentRendered() { // Post the firing of ContentRendered as Input priority work item so // that ContentRendered will be fired after render query empties. - if (_contentRenderedCallback != null) - { - // Content was changed again before the previous rendering completed (or at least - // before the Dispatcher got to Input priority callbacks). - _contentRenderedCallback.Abort(); - } + // Content was changed again before the previous rendering completed (or at least + // before the Dispatcher got to Input priority callbacks). + _contentRenderedCallback?.Abort(); _contentRenderedCallback = Dispatcher.BeginInvoke(DispatcherPriority.Input, (DispatcherOperationCallback) delegate (object arg) { @@ -4288,10 +4278,7 @@ private IntPtr WindowFilterMessage( IntPtr hwnd, { // Either Explorer's created a new button or it's time to try again. // Stop deferring updates to the Taskbar. - if (_taskbarRetryTimer != null) - { - _taskbarRetryTimer.Stop(); - } + _taskbarRetryTimer?.Stop(); // We'll receive WM_TASKBARBUTTONCREATED at times other than when the Window was created, // e.g. Explorer restarting, in response to ShowInTaskbar=true, etc. @@ -4837,10 +4824,7 @@ private bool WmMoveChanged() //This will schedule a deferred update of bounding rectangle and //corresponding notification to the Automation layer. AutomationPeer peer = UIElementAutomationPeer.FromElement(this); - if(peer != null) - { - peer.InvalidatePeer(); - } + peer?.InvalidatePeer(); } return false; @@ -6897,10 +6881,7 @@ internal void Flush() } private void ClearRootVisual() { - if (_swh != null) - { - _swh.ClearRootVisual(); - } + _swh?.ClearRootVisual(); } @@ -7070,23 +7051,17 @@ protected override void OnManipulationBoundaryFeedback(ManipulationBoundaryFeedb private static void OnStaticManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e) { Window window = sender as Window; - if (window != null) - { - // Transitioning from direct manipulation to inertia, animate the window - // back to its original position. - window.EndPanningFeedback(true); - } + // Transitioning from direct manipulation to inertia, animate the window + // back to its original position. + window?.EndPanningFeedback(true); } private static void OnStaticManipulationCompleted(object sender, ManipulationCompletedEventArgs e) { Window window = sender as Window; - if (window != null) - { - // A complete was encountered. If this was a forced complete, snap the window - // back to its original position. - window.EndPanningFeedback(false); - } + // A complete was encountered. If this was a forced complete, snap the window + // back to its original position. + window?.EndPanningFeedback(false); } /// @@ -7123,11 +7098,8 @@ private void UpdatePanningFeedback(Vector totalOverpanOffset, object originalSou /// private void EndPanningFeedback(bool animateBack) { - if (_swh != null) - { - // Restore the window to its original position - _swh.EndPanningFeedback(animateBack); - } + // Restore the window to its original position + _swh?.EndPanningFeedback(animateBack); _currentPanningTarget = null; _prePanningLocation = new Point(double.NaN, double.NaN); } @@ -7671,12 +7643,9 @@ internal void UpdatePanningFeedback(Vector totalOverpanOffset, bool animate) _panningFeedback = new HwndPanningFeedback(_sourceWindow); } - if (_panningFeedback != null) - { - // Update the window position - _panningFeedback.UpdatePanningFeedback(totalOverpanOffset, animate); - } - } + // Update the window position + _panningFeedback?.UpdatePanningFeedback(totalOverpanOffset, animate); + } /// /// Return the window back to its original position. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentManager.cs index aa052231ecc..731618788d6 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -129,10 +129,7 @@ internal static void CleanUp() { IDisposable disposable = controller as IDisposable; - if (disposable != null) - { - disposable.Dispose(); - } + disposable?.Dispose(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentProperties.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentProperties.cs index 641a55b8a58..7d418d2d203 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentProperties.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentProperties.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -315,10 +315,7 @@ internal void ShowDialog() DocumentPropertiesDialog dialog = null; dialog = new DocumentPropertiesDialog(); dialog.ShowDialog(); - if (dialog != null) - { - dialog.Dispose(); - } + dialog?.Dispose(); } #endregion Internal Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentStream.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentStream.cs index 5b2c7b79fcc..f1d40118a92 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentStream.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentStream.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -415,10 +415,7 @@ internal bool ReOpenWriteable() //---------------------------------------------------------------------- // Release Existing Locks (so we open with write) - if (Target != null) - { - Target.Close(); - } + Target?.Close(); //---------------------------------------------------------------------- // Open Writable (if it fails re-open for Read) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/RightsController.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/RightsController.cs index a1070430696..add738b32c5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/RightsController.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/RightsController.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -420,10 +420,7 @@ void IDisposable.Dispose() { IDisposable provider = _provider as IDisposable; - if (provider != null) - { - provider.Dispose(); - } + provider?.Dispose(); _provider = null; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/TransactionalPackage.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/TransactionalPackage.cs index 8e0e9311b29..9ee60bd0a39 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/TransactionalPackage.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/TransactionalPackage.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -314,10 +314,7 @@ protected override void Dispose(bool disposing) /// protected override void FlushCore() { - if (_tempPackage != null) - { - _tempPackage.Flush(); - } + _tempPackage?.Flush(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentApplicationDocumentViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentApplicationDocumentViewer.cs index f1d0e47e1f8..a49ae71fa88 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentApplicationDocumentViewer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentApplicationDocumentViewer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -304,10 +304,7 @@ protected override void OnPrintCommand() protected override void OnCancelPrintCommand() { #if !DONOTREFPRINTINGASMMETA - if (_documentWriter != null) - { - _documentWriter.CancelAsync(); - } + _documentWriter?.CancelAsync(); #endif // DONOTREFPRINTINGASMMETA } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentSignatureManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentSignatureManager.cs index ffeb863c1ca..e8ed6ccf977 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentSignatureManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentSignatureManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. // Description: @@ -249,10 +249,7 @@ internal void ShowSignatureSummaryDialog() false /*Sig Request Dialog*/); dialog.ShowDialog(parentWindow); - if (dialog != null) - { - dialog.Dispose(); - } + dialog?.Dispose(); } /// @@ -285,10 +282,7 @@ internal void ShowSignatureRequestSummaryDialog() true /*Sig Request Dialog*/); dialog.ShowDialog(parentWindow); - if (dialog != null) - { - dialog.Dispose(); - } + dialog?.Dispose(); } else { @@ -520,10 +514,7 @@ internal void ShowSigningDialog( this); dialog.ShowDialog(NativeWindow.FromHandle(parentWindow)); - if (dialog != null) - { - dialog.Dispose(); - } + dialog?.Dispose(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementManager.cs index 6ebc8c7aae1..e76772dc83d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -262,10 +262,7 @@ internal DialogResult ShowCredentialManagementUI(bool decrypting) _credManagerDialog = new CredentialManagerDialog(accountList, userAccount, this); result = _credManagerDialog.ShowDialog(); - if (_credManagerDialog != null) - { - _credManagerDialog.Dispose(); - } + _credManagerDialog?.Dispose(); RightsManagementUser newDefaultUser = _rmProvider.GetDefaultCredentials(); @@ -403,10 +400,7 @@ internal void ShowPermissions() RMPermissionsDialog rmPermissionsPage = new RMPermissionsDialog(rmLicense); rmPermissionsPage.ShowDialog(); - if (rmPermissionsPage != null) - { - rmPermissionsPage.Dispose(); - } + rmPermissionsPage?.Dispose(); } } @@ -544,10 +538,7 @@ internal void ShowPublishing() } finally { - if (rmPublish != null) - { - rmPublish.Dispose(); - } + rmPublish?.Dispose(); } // If the status changed, call Evaluate to re-evaluate the RM @@ -588,13 +579,10 @@ internal void OnCredentialManagementRemove(string accountName) { _rmProvider.RemoveCredentials(user); - if (_credManagerDialog != null) - { - //Set the data source for the listbox - _credManagerDialog.SetCredentialManagementList( - GetCredentialManagementResourceList(), - GetDefaultCredentialManagementResource()); - } + //Set the data source for the listbox + _credManagerDialog?.SetCredentialManagementList( + GetCredentialManagementResourceList(), + GetDefaultCredentialManagementResource()); } catch (RightsManagementException exception) { @@ -624,13 +612,10 @@ internal void OnCredentialManagementShowEnrollment() { ShowEnrollment(); - if (_credManagerDialog != null) - { - //Set the data source for the listbox - _credManagerDialog.SetCredentialManagementList( - GetCredentialManagementResourceList(), - GetDefaultCredentialManagementResource()); - } + //Set the data source for the listbox + _credManagerDialog?.SetCredentialManagementList( + GetCredentialManagementResourceList(), + GetDefaultCredentialManagementResource()); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/BrushProxy.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/BrushProxy.cs index 8c68ec9750c..2eb68ce697b 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/BrushProxy.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/BrushProxy.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -809,10 +809,7 @@ public void ApplyTransform(Matrix trans) } } - if (_opacityMask != null) - { - _opacityMask.ApplyTransform(trans); - } + _opacityMask?.ApplyTransform(trans); } } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Flattener.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Flattener.cs index 5c427fb74e1..5d1f6f4bde6 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Flattener.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Flattener.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -168,10 +168,7 @@ public void TreeFlatten(Primitive tree, Geometry clip, Matrix transform, double } #endif - if (opacityMask != null) - { - opacityMask.ApplyTransform(transform); - } + opacityMask?.ApplyTransform(transform); // Flatten sub-tree structure into a new DisplayList fl.TreeFlatten(ntree, clip, transform, 1.0, null); @@ -361,10 +358,7 @@ public void AlphaFlatten(IProxyDrawingContext dc, bool disjoint) #if DEBUG for (int i = 0; i < count; i ++) { - if (commands[i] != null) - { - commands[i].SetID(i); - } + commands[i]?.SetID(i); } Console.WriteLine(); @@ -691,7 +685,7 @@ private static bool ConvertTransparentOnOpaque(List commands, int { // Blend it with brush underneath BrushProxy blendedBrush = gp.Brush; - BrushProxy blendedPenBrush = gp.Pen == null ? null : gp.Pen.StrokeBrush; + BrushProxy blendedPenBrush = gp.Pen?.StrokeBrush; if (blendedBrush != null) { diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/MetroDevice.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/MetroDevice.cs index 3b5f035378c..0fa5d461306 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/MetroDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/MetroDevice.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -633,7 +633,7 @@ public void StartPage(PrintTicket ticket) { Toolbox.EmitEvent(EventTrace.Event.WClientDRXStartPageBegin); - String printTicketXMLStr = (ticket == null) ? null : ticket.ToXmlString(); + String printTicketXMLStr = ticket?.ToXmlString(); CaptureTicketSettings(ticket, printTicketXMLStr); diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Primitive.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Primitive.cs index dec4ba925a6..57bc3658649 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Primitive.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Primitive.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1092,10 +1092,7 @@ private void AbsorbOpacity() Brush = Brush.PushOpacity(Opacity, OpacityMask); } - if (Pen != null) - { - Pen.PushOpacity(Opacity, OpacityMask); - } + Pen?.PushOpacity(Opacity, OpacityMask); Opacity = 1; OpacityMask = null; @@ -1330,10 +1327,7 @@ public override void ApplyTransform() // Clip = Utility.TransformGeometry(Clip, Transform); Geometry = Utility.TransformGeometry(Geometry, Transform); - if (Brush != null) - { - Brush.ApplyTransform(Transform); - } + Brush?.ApplyTransform(Transform); Transform = Matrix.Identity; // Reset transform _widenGeometry = null; // Reset cached widen geometry if any diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/SegmentTree.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/SegmentTree.cs index 4dfb9c78ad9..f5a263df128 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/SegmentTree.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/SegmentTree.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -69,10 +69,7 @@ public void Remove(int index, double x0, double x1) { if ((_min >= x0) && (_max <= x1)) // [_min.._max] is within [x0..x1] { - if (_sList != null) - { - _sList.Remove(index); - } + _sList?.Remove(index); } else { diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/HGlobalBuffer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/HGlobalBuffer.cs index 59b2808bad9..536632c1f20 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/HGlobalBuffer.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/HGlobalBuffer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -49,10 +49,7 @@ public void Release() SafeHandle handle = this.Handle; this.Handle = null; - if (handle != null) - { - handle.Dispose(); - } + handle?.Dispose(); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/PartEditor.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/PartEditor.cs index 547555715d3..a9c1ff8f131 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/PartEditor.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/PartEditor.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -117,10 +117,7 @@ internal Stream DataStream Flush( ) { - if (null != _partDataStream) - { - _partDataStream.Flush(); - } + _partDataStream?.Flush(); } #endregion Internal methods @@ -291,10 +288,7 @@ string namespaceUri Flush( ) { - if (null != _xmlWriter) - { - _xmlWriter.Flush(); - } + _xmlWriter?.Flush(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsDocument.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsDocument.cs index 1df644c1197..c175085df6c 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsDocument.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsDocument.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -889,10 +889,7 @@ Stream dataStream DisposeXpsDocument( ) { - if(_opcPackage != null) - { - _opcPackage.Close(); - } + _opcPackage?.Close(); } internal diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs index dffa09711c9..774251b77fa 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1335,10 +1335,7 @@ Uri uri _currentChildren = null; } #if !RESOURCESTREAM_USING_PART - if (_pageStream != null) - { - _pageStream.Close(); - } + _pageStream?.Close(); #endif Toolbox.EmitEvent(EventTrace.Event.WClientDRXCommitPageEnd); } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsResource.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsResource.cs index 62a194ee2c5..bbb4bfffcfb 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsResource.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsResource.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -133,13 +133,10 @@ Uri inUri INode.Flush( ) { - if( _partEditor != null ) - { - // - // Flush the part editor - // - _partEditor.Flush(); - } + // + // Flush the part editor + // + _partEditor?.Flush(); } void @@ -163,10 +160,7 @@ Uri inUri void IDisposable.Dispose() { - if (_partEditor != null) - { - _partEditor.Close(); - } + _partEditor?.Close(); GC.SuppressFinalize(this); } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs index 037ebe17ca8..3b6efea546f 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -350,10 +350,7 @@ public override byte[] ConvertPrintTicketToDevMode(MemoryStream printTicket, public override void Release() { - if (_deviceHandle != null) - { - _deviceHandle.Dispose(); - } + _deviceHandle?.Dispose(); this._deviceHandle = null; this._deviceName = null; diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrtTicket_Base.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrtTicket_Base.cs index 97616d6f50a..dcaac364d58 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrtTicket_Base.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrtTicket_Base.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1108,10 +1108,7 @@ internal int IntValue PrintTicketParameterNode.CreateParameterNode(this); } - if (ParameterNode != null) - { - ParameterNode.SetIntValue(value); - } + ParameterNode?.SetIntValue(value); } } @@ -1164,10 +1161,7 @@ internal string StringValue PrintTicketParameterNode.CreateParameterNode(this); } - if (ParameterNode != null) - { - ParameterNode.SetStringValue(value, PrintSchemaXsiTypes.String); - } + ParameterNode?.SetStringValue(value, PrintSchemaXsiTypes.String); } } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintSystemExceptions/PrintSystemException.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintSystemExceptions/PrintSystemException.cs index ea2c5dbb684..878794791b4 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintSystemExceptions/PrintSystemException.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintSystemExceptions/PrintSystemException.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -407,10 +407,7 @@ public override System.Runtime.Serialization.StreamingContext context ) { - if (info != null) - { - info.AddValue("PrinterName", printerName); - } + info?.AddValue("PrinterName", printerName); base.GetObjectData(info, context); } #pragma warning restore SYSLIB0051 // Type or member is obsolete @@ -574,10 +571,7 @@ public override System.Runtime.Serialization.StreamingContext context ) { - if (info != null) - { - info.AddValue("ServerName", serverName); - } + info?.AddValue("ServerName", serverName); base.GetObjectData(info, context); } @@ -933,10 +927,7 @@ public override System.Runtime.Serialization.StreamingContext context ) { - if( info != null ) - { - info.AddValue("JobId", jobId ); - } + info?.AddValue("JobId", jobId ); base.GetObjectData(info, context); } #pragma warning restore SYSLIB0051 // Type or member is obsolete diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/XpsFontSubsetter.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/XpsFontSubsetter.cs index acf1f5df59d..3ca4ec489ff 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/XpsFontSubsetter.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/XpsFontSubsetter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -203,10 +203,7 @@ FontSubsetterCommitPolicies signal { foreach (FEMCacheItem item in _fontEmbeddingManagerCache.Values) { - if (item != null) - { - item.AddRestrictedRelationship(); - } + item?.AddRestrictedRelationship(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializer.cs index eb6322d9365..0e3f6c6d453 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -405,10 +405,7 @@ Object serializedObject ReachSerializer serializer = SerializationManager.GetSerializer(page); - if (serializer != null) - { - serializer.SerializeObject(page); - } + serializer?.SerializeObject(page); } } @@ -604,18 +601,12 @@ DocumentReference dre if (fixedDoc != null) { ReachSerializer serializer = SerializationManager.GetSerializer(fixedDoc); - if (serializer != null) - { - serializer.SerializeObject(fixedDoc); - } + serializer?.SerializeObject(fixedDoc); } else { ReachSerializer serializer = SerializationManager.GetSerializer(idp.DocumentPaginator); - if (serializer != null) - { - serializer.SerializeObject(idp); - } + serializer?.SerializeObject(idp); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializerAsync.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializerAsync.cs index 01648adea2b..26472e859b8 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializerAsync.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializerAsync.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -438,10 +438,7 @@ SerializablePropertyContext serializablePropertyContext ReachSerializer serializer = SerializationManager.GetSerializer(serializablePropertyContext.Value); // If there is no serializer for this type, we won't serialize this property - if(serializer!=null) - { - serializer.SerializeObject(serializablePropertyContext); - } + serializer?.SerializeObject(serializablePropertyContext); } } @@ -730,10 +727,7 @@ NGCSerializerContext context ReachSerializer serializer = SerializationManager.GetSerializer(page); - if (serializer != null) - { - serializer.SerializeObject(page); - } + serializer?.SerializeObject(page); } } else @@ -1309,18 +1303,12 @@ object documentReference if (fixedDoc != null) { ReachSerializer serializer = NgcSerializationManager.GetSerializer(fixedDoc); - if (serializer != null) - { - serializer.SerializeObject(fixedDoc); - } + serializer?.SerializeObject(fixedDoc); } else { ReachSerializer serializer = NgcSerializationManager.GetSerializer(idp.DocumentPaginator); - if (serializer != null) - { - serializer.SerializeObject(idp); - } + serializer?.SerializeObject(idp); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NullPackagingPolicy.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NullPackagingPolicy.cs index b793ae525c1..c44169b65c6 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NullPackagingPolicy.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NullPackagingPolicy.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -900,25 +900,13 @@ PrintTicket printTicket _currentXpsColorContextRef = 0; _currentXpsResourceDictionaryRef = 0; - if(_fontResourceStream!=null) - { - _fontResourceStream.Initialize(); - } + _fontResourceStream?.Initialize(); - if(_imageResourceStream!=null) - { - _imageResourceStream.Initialize(); - } + _imageResourceStream?.Initialize(); - if(_colorContextResourceStream!=null) - { - _colorContextResourceStream.Initialize(); - } + _colorContextResourceStream?.Initialize(); - if(_resourceDictionaryResourceStream!=null) - { - _resourceDictionaryResourceStream.Initialize(); - } + _resourceDictionaryResourceStream?.Initialize(); _fontAcquireMode = ResourceAcquireMode.NoneAcquired; diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentPageSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentPageSerializer.cs index 5dc5a0a68fe..2af31eccd27 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentPageSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentPageSerializer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -190,10 +190,7 @@ private void SerializeChild(Visual child, SerializableObjectContext parentContex { ReachSerializer serializer = SerializationManager.GetSerializer(child); - if (serializer != null) - { - serializer.SerializeObject(child); - } + serializer?.SerializeObject(child); } private void WriteAttribute(XmlWriter writer, string name, object value) diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentPageSerializerAsync.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentPageSerializerAsync.cs index a97bb61b7e2..dc8dbb22d47 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentPageSerializerAsync.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentPageSerializerAsync.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -228,10 +228,7 @@ private void SerializeChild(Visual child, SerializableObjectContext parentContex { ReachSerializer serializer = SerializationManager.GetSerializer(child); - if (serializer != null) - { - serializer.SerializeObject(child); - } + serializer?.SerializeObject(child); } private diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachIDocumentPaginatorSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachIDocumentPaginatorSerializer.cs index 6490df13d0c..6df80dcf539 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachIDocumentPaginatorSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachIDocumentPaginatorSerializer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -124,10 +124,7 @@ SerializableObjectContext serializableObjectContext ReachSerializer serializer = SerializationManager.GetSerializer(page); - if (serializer != null) - { - serializer.SerializeObject(page); - } + serializer?.SerializeObject(page); } } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachIDocumentPaginatorSerializerAsync.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachIDocumentPaginatorSerializerAsync.cs index edf1f92c5c9..cbf0838fa8d 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachIDocumentPaginatorSerializerAsync.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachIDocumentPaginatorSerializerAsync.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -259,10 +259,7 @@ ReachSerializerContext context DocumentPage page = Toolbox.GetPage(paginator, index-1); ReachSerializer serializer = SerializationManager.GetSerializer(page); - if (serializer != null) - { - serializer.SerializeObject(page); - } + serializer?.SerializeObject(page); } } else diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachObjectContext.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachObjectContext.cs index 640dd666ff5..4b4308db0c9 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachObjectContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachObjectContext.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -159,7 +159,7 @@ SerializablePropertyContext serializablePropertyContext // Namespace related creation within the context // MetroSerializationNamespaceTable parentNamespaceTable = - serializableObjectParentContext != null ? serializableObjectParentContext.NamespaceTable : null; + serializableObjectParentContext?.NamespaceTable; if (serializableObjectContext.NamespaceTable == null) { @@ -347,10 +347,7 @@ SerializablePropertyContext serializablePropertyContext _isReadOnlyValue = false; _namespaceTable = null; - if (_propertiesCollection != null) - { - _propertiesCollection.Clear(); - } + _propertiesCollection?.Clear(); base.Clear(); } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializer.cs index 3dffaf48e83..d91fd9b24ad 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -343,10 +343,7 @@ SerializablePropertyContext serializablePropertyContext ReachSerializer serializer = SerializationManager.GetSerializer(serializablePropertyContext.Value); // If there is no serializer for this type, we won't serialize this property - if(serializer!=null) - { - serializer.SerializeObject(serializablePropertyContext); - } + serializer?.SerializeObject(serializablePropertyContext); } } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializerAsync.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializerAsync.cs index b9526c72c71..0bc4d7d48ec 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializerAsync.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializerAsync.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -450,10 +450,7 @@ SerializablePropertyContext serializablePropertyContext ReachSerializer serializer = SerializationManager.GetSerializer(serializablePropertyContext.Value); // If there is no serializer for this type, we won't serialize this property - if(serializer!=null) - { - serializer.SerializeObject(serializablePropertyContext); - } + serializer?.SerializeObject(serializablePropertyContext); } } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPageSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPageSerializer.cs index 29b56385584..414abb524fc 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPageSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPageSerializer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -215,10 +215,7 @@ SerializableObjectContext parentContext { ReachSerializer serializer = SerializationManager.GetSerializer(child); - if (serializer != null) - { - serializer.SerializeObject(child); - } + serializer?.SerializeObject(child); } private diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPaginatorSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPaginatorSerializer.cs index 0cce9f98dce..103bf1b2a37 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPaginatorSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPaginatorSerializer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -79,10 +79,7 @@ SerializableObjectContext serializableObjectContext ReachSerializer serializer = SerializationManager.GetSerializer(page); - if (serializer != null) - { - serializer.SerializeObject(page); - } + serializer?.SerializeObject(page); } EndPersistObjectData(); diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPaginatorSerializerAsync.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPaginatorSerializerAsync.cs index 469d11e78be..1e04d601d9e 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPaginatorSerializerAsync.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMDocumentPaginatorSerializerAsync.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -138,10 +138,7 @@ ReachSerializerContext context DocumentPage page = Toolbox.GetPage(paginator, index - 1); ReachSerializer serializer = SerializationManager.GetSerializer(page); - if (serializer != null) - { - serializer.SerializeObject(page); - } + serializer?.SerializeObject(page); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs index 298f3bb40c5..b7291bce2d8 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -734,26 +734,17 @@ string resourceId _currentFixedPageUri = null; _currentXpsImageRef = 0; - if (_imageResourceStream != null) - { - _imageResourceStream.Stream.Dispose(); - } + _imageResourceStream?.Stream.Dispose(); _imageResourceStream = null; _currentXpsColorContextRef = 0; - if (_colorContextResourceStream != null) - { - _colorContextResourceStream.Stream.Dispose(); - } + _colorContextResourceStream?.Stream.Dispose(); _colorContextResourceStream = null; _currentPageContentStream = null; _currentResourceStream = null; - if (_currentFixedPagePrintStream != null) - { - _currentFixedPagePrintStream.Dispose(); - } + _currentFixedPagePrintStream?.Dispose(); _currentFixedPagePrintStream = null; _currentPageContentXmlWriter = null; _currentResourceXmlWriter = null; diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsPackagingPolicy.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsPackagingPolicy.cs index 1b4f0eaa068..1e57dd3f88b 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsPackagingPolicy.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsPackagingPolicy.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1443,25 +1443,13 @@ PackagingProgressEventHandler PackagingProgressEvent _currentXpsColorContextRef = 0; _currentXpsResourceDictionaryRef = 0; - if(_fontResourceStream!=null) - { - _fontResourceStream.Initialize(); - } + _fontResourceStream?.Initialize(); - if(_imageResourceStream!=null) - { - _imageResourceStream.Initialize(); - } + _imageResourceStream?.Initialize(); - if(_colorContextResourceStream!=null) - { - _colorContextResourceStream.Initialize(); - } + _colorContextResourceStream?.Initialize(); - if(_resourceDictionaryResourceStream!=null) - { - _resourceDictionaryResourceStream.Initialize(); - } + _resourceDictionaryResourceStream?.Initialize(); } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsSerializationManager.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsSerializationManager.cs index f7e4e9f9e48..e48cae8c92e 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsSerializationManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsSerializationManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -577,10 +577,7 @@ Type writerType if( subsetComplete && refCnt == 0 ) { XpsPackagingPolicy xpsPackagingPolicy = _packagingPolicy as XpsPackagingPolicy; - if(xpsPackagingPolicy != null ) - { - xpsPackagingPolicy.InterleavingPolicy.SignalSubsetComplete(); - } + xpsPackagingPolicy?.InterleavingPolicy.SignalSubsetComplete(); } Toolbox.EmitEvent(EventTrace.Event.WClientDRXReleaseWriterEnd); @@ -839,10 +836,7 @@ ReachSerializationServices reachSerializationServices string relationshipName ) { - if (_packagingPolicy != null) - { - _packagingPolicy.RelateResourceToCurrentPage(targetUri, relationshipName); - } + _packagingPolicy?.RelateResourceToCurrentPage(targetUri, relationshipName); } internal diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/SerializerFactory/XpsSerializerWriter.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/SerializerFactory/XpsSerializerWriter.cs index 2e517078cb2..e73ae7185f1 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/SerializerFactory/XpsSerializerWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/SerializerFactory/XpsSerializerWriter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -441,18 +441,12 @@ public override SerializerWriterCollator CreateVisualsCollator(PrintTicket docum private void xsw_WritingPrintTicketRequired(object sender, WritingPrintTicketRequiredEventArgs e) { - if (WritingPrintTicketRequired != null) - { - WritingPrintTicketRequired.Invoke(sender, e); - } + WritingPrintTicketRequired?.Invoke(sender, e); } private void xsw_WritingProgressChanged(object sender, WritingProgressChangedEventArgs e) { - if ( WritingProgressChanged != null) - { - WritingProgressChanged.Invoke(sender, e); - } + WritingProgressChanged?.Invoke(sender, e); } private void xsw_WritingCompleted(object sender, WritingCompletedEventArgs e) diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/IO/Packaging/PackagingUtilities.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/IO/Packaging/PackagingUtilities.cs index f95650bc363..8d682660c75 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/IO/Packaging/PackagingUtilities.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/IO/Packaging/PackagingUtilities.cs @@ -534,8 +534,7 @@ private static bool UserHasProfile() } finally { - if (userProfileKey != null) - userProfileKey.Close(); + userProfileKey?.Close(); } return userHasProfile; diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/ReaderWriterLockSlimWrapper.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/ReaderWriterLockSlimWrapper.cs index 4bc77449274..654199631e5 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/ReaderWriterLockSlimWrapper.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/ReaderWriterLockSlimWrapper.cs @@ -308,10 +308,7 @@ private bool ExecuteWithinLockInternal(Action lockAcquire, Action lockRelease, r } finally { - if (dispatcherProcessingDisabled != null) - { - dispatcherProcessingDisabled.Value.Dispose(); - } + dispatcherProcessingDisabled?.Dispose(); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalList.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalList.cs index e08c8c8ed5b..d98aabe20f0 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalList.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalList.cs @@ -1767,10 +1767,7 @@ public int Add(T value) public void Clear() { - if (null != _listStore) - { - _listStore.Clear(); - } + _listStore?.Clear(); } public bool Contains(T value) @@ -1904,7 +1901,7 @@ public Compacter(FrugalObjectList list, int newCount) _list = list; FrugalListBase store = _list._listStore; - _storeCompacter = (store != null) ? store.NewCompacter(newCount) : null; + _storeCompacter = store?.NewCompacter(newCount); } public void Include(int start, int end) @@ -2139,10 +2136,7 @@ public int Add(T value) public void Clear() { - if (null != _listStore) - { - _listStore.Clear(); - } + _listStore?.Clear(); } public bool Contains(T value) diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalMap.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalMap.cs index 55ac7effda2..77cdb96d68b 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalMap.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalMap.cs @@ -1753,10 +1753,7 @@ public object this[int key] public void Sort() { - if (null != _mapStore) - { - _mapStore.Sort(); - } + _mapStore?.Sort(); } public void GetKeyValuePair(int index, out int key, out Object value) @@ -1777,10 +1774,7 @@ public void Iterate(ArrayList list, FrugalMapIterationCallback callback) { if (null != list) { - if (_mapStore != null) - { - _mapStore.Iterate(list, callback); - } + _mapStore?.Iterate(list, callback); } else { @@ -2102,10 +2096,7 @@ public object this[int key] public void Sort() { - if (null != _mapStore) - { - _mapStore.Sort(); - } + _mapStore?.Sort(); } public void GetKeyValuePair(int index, out int key, out Object value) @@ -2126,10 +2117,7 @@ public void Iterate(ArrayList list, FrugalMapIterationCallback callback) { if (null != list) { - if (_mapStore != null) - { - _mapStore.Iterate(list, callback); - } + _mapStore?.Iterate(list, callback); } else { diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/Maps.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/Maps.cs index d60f108c944..3629776967e 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/Maps.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/Maps.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -93,10 +93,7 @@ public void Clear() _activeDTypes.List[i] = null; } - if (_overFlow != null) - { - _overFlow.Clear(); - } + _overFlow?.Clear(); } private int _entryCount; diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/XmlWrappingReader.cs b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/XmlWrappingReader.cs index 34ee0665668..24523da74bd 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/XmlWrappingReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/XmlWrappingReader.cs @@ -117,11 +117,11 @@ public override string LookupNamespace( string prefix ) { } string IXmlNamespaceResolver.LookupPrefix( string namespaceName ) { - return (_readerAsResolver == null) ? null : _readerAsResolver.LookupPrefix( namespaceName ); + return _readerAsResolver?.LookupPrefix( namespaceName ); } IDictionary IXmlNamespaceResolver.GetNamespacesInScope ( XmlNamespaceScope scope ) { - return (_readerAsResolver == null) ? null : _readerAsResolver.GetNamespacesInScope( scope ); + return _readerAsResolver?.GetNamespacesInScope( scope ); } public override void ResolveEntity() { diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonAutomationPeer.cs index 02dc44074b6..713173769cd 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -133,10 +133,7 @@ protected override System.Collections.Generic.List GetChildrenCo { #if RIBBON_IN_FRAMEWORK AutomationPeer peer = CreatePeerForElement(OwningRibbon.RibbonTabHeaderItemsControl); - if (peer != null) - { - peer.ForceEnsureChildren(); - } + peer?.ForceEnsureChildren(); #else // We are unable to use this commented piece of code because ForceEnsureChildren // is an internal method in .Net 4.0. The public alternative is to use diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryCategoryDataAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryCategoryDataAutomationPeer.cs index b043872b913..7525ed9edcf 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryCategoryDataAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryCategoryDataAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -77,10 +77,7 @@ override public object GetPattern(PatternInterface patternInterface) void IScrollItemProvider.ScrollIntoView() { RibbonGalleryCategory category = GetWrapper() as RibbonGalleryCategory; - if (category != null) - { - category.BringIntoView(); - } + category?.BringIntoView(); } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryItemAutomationPeer.cs index efba67362bf..075d56af65b 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryItemAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryItemAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -100,23 +100,17 @@ override protected bool IsOffscreenCore() [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] internal void RaiseAutomationIsSelectedChanged(bool isSelected) { - if (EventsSource != null) - { - EventsSource.RaisePropertyChangedEvent( + EventsSource?.RaisePropertyChangedEvent( SelectionItemPatternIdentifiers.IsSelectedProperty, !isSelected, isSelected); - } } // Selection Events needs to be raised on DataItem Peers now when they exist. internal void RaiseAutomationSelectionEvent(AutomationEvents eventId) { - if (EventsSource != null) - { - EventsSource.RaiseAutomationEvent(eventId); - } + EventsSource?.RaiseAutomationEvent(eventId); } #endregion Selection Events diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryItemDataAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryItemDataAutomationPeer.cs index a917bc7c365..d8c2fa6338b 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryItemDataAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGalleryItemDataAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -84,10 +84,7 @@ public RibbonGalleryCategoryDataAutomationPeer ParentCategoryDataAutomationPeer void IScrollItemProvider.ScrollIntoView() { RibbonGalleryItem ribbonGalleryItem = GetWrapper() as RibbonGalleryItem; - if (ribbonGalleryItem != null) - { - ribbonGalleryItem.BringIntoView(); - } + ribbonGalleryItem?.BringIntoView(); } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGroupAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGroupAutomationPeer.cs index 87c7474b12f..2ccace98fe0 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGroupAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGroupAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -129,13 +129,10 @@ RibbonGroupHeaderAutomationPeer HeaderPeer internal void RaiseExpandCollapseAutomationEvent(bool oldValue, bool newValue) { AutomationPeer dataPeer = EventsSource; - if (dataPeer != null) - { - dataPeer.RaisePropertyChangedEvent( + dataPeer?.RaisePropertyChangedEvent( ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, oldValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed, newValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed); - } } private RibbonGroupHeaderAutomationPeer _headerPeer; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGroupDataAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGroupDataAutomationPeer.cs index c33ef68af88..4e86d89be03 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGroupDataAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonGroupDataAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -86,10 +86,7 @@ protected override string GetClassNameCore() void IScrollItemProvider.ScrollIntoView() { RibbonGroup wrapper = GetWrapper() as RibbonGroup; - if (wrapper != null) - { - wrapper.BringIntoView(); - } + wrapper?.BringIntoView(); } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonMenuItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonMenuItemAutomationPeer.cs index 27301155adb..8513b8cd134 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonMenuItemAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonMenuItemAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -98,13 +98,10 @@ internal void RaiseExpandCollapseAutomationEvent(bool oldValue, bool newValue) { AutomationPeer dataPeer = EventsSource; - if (dataPeer != null) - { - dataPeer.RaisePropertyChangedEvent( + dataPeer?.RaisePropertyChangedEvent( ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, oldValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed, newValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed); - } } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] @@ -112,10 +109,7 @@ internal void RaiseToggleStatePropertyChangedEvent(bool oldValue, bool newValue) { AutomationPeer dataPeer = EventsSource; - if (dataPeer != null) - { - dataPeer.RaisePropertyChangedEvent(TogglePatternIdentifiers.ToggleStateProperty, ConvertToToggleState(oldValue), ConvertToToggleState(newValue)); - } + dataPeer?.RaisePropertyChangedEvent(TogglePatternIdentifiers.ToggleStateProperty, ConvertToToggleState(oldValue), ConvertToToggleState(newValue)); } private static ToggleState ConvertToToggleState(bool value) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonTabAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonTabAutomationPeer.cs index 1f26b1b8695..0ab8a55e4c8 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonTabAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonTabAutomationPeer.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -140,13 +140,10 @@ internal void RaiseTabExpandCollapseAutomationEvent(bool oldValue, bool newValue { AutomationPeer dataPeer = EventsSource; - if (dataPeer != null) - { - dataPeer.RaisePropertyChangedEvent( + dataPeer?.RaisePropertyChangedEvent( ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, oldValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed, newValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed); - } } // Never inline, as we don't want to unnecessarily link the diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Generated/TreeHelper.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Generated/TreeHelper.cs index fea0d9ad046..10c36375eb9 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Generated/TreeHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Generated/TreeHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -212,10 +212,7 @@ public static void InvalidateMeasureForVisualAncestorPath(Dependenc return; } UIElement element = pathStart as UIElement; - if (element != null) - { - element.InvalidateMeasure(); - } + element?.InvalidateMeasure(); if (isEndType) { return; @@ -236,10 +233,7 @@ public static void InvalidateMeasureForVisualAncestorPath(DependencyObject pathS while (pathStart != null) { UIElement element = pathStart as UIElement; - if (element != null) - { - element.InvalidateMeasure(); - } + element?.InvalidateMeasure(); if (predicate(pathStart)) { diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipAdorner.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipAdorner.cs index 49a41769b12..68241d4fd8e 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipAdorner.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipAdorner.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -76,10 +76,7 @@ protected override Size MeasureOverride(Size constraint) protected override Size ArrangeOverride(Size finalSize) { - if (_keyTipControl != null) - { - _keyTipControl.Arrange(new Rect(_keyTipControl.DesiredSize)); - } + _keyTipControl?.Arrange(new Rect(_keyTipControl.DesiredSize)); return finalSize; } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipService.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipService.cs index 45391bf4528..fff65eb52cc 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipService.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipService.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -152,10 +152,7 @@ private static void OnKeyTipScopeChanged(DependencyObject d, DependencyPropertyC WeakHashSet oldElementSet = null; if (current._scopeToElementMap.TryGetValue(oldScope, out oldElementSet)) { - if (oldElementSet != null) - { - oldElementSet.Remove(d); - } + oldElementSet?.Remove(d); } } if (newScope != null) @@ -1105,10 +1102,7 @@ private void StartShowKeyTipsTimer() private void ShowKeyTips() { - if (_showKeyTipsTimer != null) - { - _showKeyTipsTimer.Stop(); - } + _showKeyTipsTimer?.Stop(); if (State == KeyTipState.Pending) { Debug.Assert(_currentGlobalScope != null); @@ -1234,10 +1228,7 @@ private void Reset() _currentWindow.LocationChanged -= new EventHandler(OnWindowLocationChanged); } _currentWindow = null; - if (_showKeyTipsTimer != null) - { - _showKeyTipsTimer.Stop(); - } + _showKeyTipsTimer?.Stop(); _focusRibbonOnKeyTipKeyUp = false; _modeEnterKey = Key.None; _probableModeEnterKey = Key.None; @@ -1367,10 +1358,7 @@ private static void OnShowingKeyTipChanged(DependencyObject element, DependencyP // Raise the ActivatingKeyTip event. ActivatingKeyTipEventArgs activatingEventArgs = new ActivatingKeyTipEventArgs(); IInputElement inputElement = element as IInputElement; - if (inputElement != null) - { - inputElement.RaiseEvent(activatingEventArgs); - } + inputElement?.RaiseEvent(activatingEventArgs); // KeyTips could have been dismissed due to one // of the event handler, hence check again. @@ -1437,10 +1425,7 @@ private static void OnShowingKeyTipChanged(DependencyObject element, DependencyP UnlinkKeyTipControlFromAdorner(adorner); bool isScrollAdornerLayer = false; AdornerLayer adornerLayer = GetAdornerLayer(adornedElement, out isScrollAdornerLayer); - if (adornerLayer != null) - { - adornerLayer.Remove(adorner); - } + adornerLayer?.Remove(adorner); } element.ClearValue(KeyTipAdornerProperty); element.ClearValue(KeyTipAdornerHolderProperty); @@ -1467,10 +1452,7 @@ private void EnqueueAdornerLayerForPlacementProcessing(AdornerLayer adornerLayer foreach (object child in LogicalTreeHelper.GetChildren(currentAdornerLayer)) { KeyTipAdorner keyTipAdorner = child as KeyTipAdorner; - if (keyTipAdorner != null) - { - keyTipAdorner.NudgeIntoAdornerLayerBoundary(currentAdornerLayer); - } + keyTipAdorner?.NudgeIntoAdornerLayerBoundary(currentAdornerLayer); } } _placementProcessingAdornerLayers.Clear(); diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonContextualTabGroupsPanel.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonContextualTabGroupsPanel.cs index cd8d91ae59b..1a82c4b9987 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonContextualTabGroupsPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonContextualTabGroupsPanel.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -90,10 +90,7 @@ protected override Size MeasureOverride(Size availableSize) if (WaitingForMeasure || invalidateTHPanel) { - if (tabHeadersPanel != null) - { - tabHeadersPanel.InvalidateMeasure(); - } + tabHeadersPanel?.InvalidateMeasure(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGalleryCategoriesPanel.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGalleryCategoriesPanel.cs index 0271dfc1177..4670971c34e 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGalleryCategoriesPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGalleryCategoriesPanel.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -133,7 +133,7 @@ private static void ResetScrolling(RibbonGalleryCategoriesPanel element) // At the time this method is called, scrolling state is in its new, valid state. private void OnScrollChange() { - if (ScrollOwner != null) { ScrollOwner.InvalidateScrollInfo(); } + ScrollOwner?.InvalidateScrollInfo(); } private void VerifyScrollingData(Size viewport, Size extent, Vector offset) @@ -619,10 +619,7 @@ public void OnInitializeLayout() { TreeHelper.InvalidateMeasureForVisualAncestorPath(this, RibbonHelper.IsISupportStarLayout); RibbonGallery gallery = this.Gallery; - if (gallery != null) - { - gallery.InvalidateMeasureOnAllCategoriesPanel(); - } + gallery?.InvalidateMeasureOnAllCategoriesPanel(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonQuickAccessToolBarPanel.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonQuickAccessToolBarPanel.cs index 3cf24882a7e..67b63369e3e 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonQuickAccessToolBarPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonQuickAccessToolBarPanel.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -176,7 +176,7 @@ protected override Size MeasureOverride(Size availableSize) UIElementCollection children = InternalChildren; List generatedItems = GeneratedChildren; int overflowIndex = 0; - RibbonQuickAccessToolBarOverflowPanel overflowPanel = QAT == null ? null : QAT.OverflowPanel; + RibbonQuickAccessToolBarOverflowPanel overflowPanel = QAT?.OverflowPanel; for (int i = 0; i < generatedItems.Count; i++) { @@ -246,10 +246,7 @@ protected override Size MeasureOverride(Size availableSize) Dispatcher.BeginInvoke((Action)delegate() { UIElement parent = VisualTreeHelper.GetParent(this) as UIElement; - if (parent != null) - { - parent.InvalidateMeasure(); - } + parent?.InvalidateMeasure(); }, DispatcherPriority.Normal, null); diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonTabHeadersPanel.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonTabHeadersPanel.cs index dabb93eb95b..d1b546dfaa2 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonTabHeadersPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonTabHeadersPanel.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -810,10 +810,7 @@ private void VerifyScrollData(double viewportWidth, double extentWidth) if (!fValid) { - if (ScrollOwner != null) - { - ScrollOwner.InvalidateScrollInfo(); - } + ScrollOwner?.InvalidateScrollInfo(); } } @@ -841,10 +838,7 @@ public ScrollViewer ScrollOwner { if (ScrollData._scrollOwner != value) { - if (Ribbon != null) - { - Ribbon.NotifyTabHeadersScrollOwnerChanged(ScrollData._scrollOwner, value); - } + Ribbon?.NotifyTabHeadersScrollOwnerChanged(ScrollData._scrollOwner, value); ScrollData._scrollOwner = value; } } @@ -931,7 +925,7 @@ public Rect MakeVisible(Visual visual, Rect rectangle) private void OnScrollChange() { - if (ScrollOwner != null) { ScrollOwner.InvalidateScrollInfo(); } + ScrollOwner?.InvalidateScrollInfo(); } internal static double ComputeScrollOffsetWithMinimalScroll( diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonTabsPanel.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonTabsPanel.cs index 01a92a268b9..d9adb943daa 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonTabsPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonTabsPanel.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -168,7 +168,7 @@ public Rect MakeVisible(Visual visual, Rect rectangle) private void OnScrollChange() { - if (ScrollOwner != null) { ScrollOwner.InvalidateScrollInfo(); } + ScrollOwner?.InvalidateScrollInfo(); } internal static double ComputeScrollOffsetWithMinimalScroll( diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Ribbon.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Ribbon.cs index bedc891783d..bbebf01adba 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Ribbon.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Ribbon.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -986,10 +986,7 @@ protected override void OnPreviewMouseWheel(MouseWheelEventArgs e) if (newSelectedIndex >= 0) { SelectedIndex = newSelectedIndex; - if (_tabHeaderItemsControl != null) - { - _tabHeaderItemsControl.ScrollIntoView(SelectedIndex); - } + _tabHeaderItemsControl?.ScrollIntoView(SelectedIndex); } } } @@ -1004,10 +1001,7 @@ protected override void OnPreviewMouseWheel(MouseWheelEventArgs e) if (newSelectedIndex >= 0) { SelectedIndex = newSelectedIndex; - if (_tabHeaderItemsControl != null) - { - _tabHeaderItemsControl.ScrollIntoView(SelectedIndex); - } + _tabHeaderItemsControl?.ScrollIntoView(SelectedIndex); } } } @@ -1080,10 +1074,7 @@ protected override void PrepareContainerForItemOverride(DependencyObject element } RibbonTab container = element as RibbonTab; - if (container != null) - { - container.PrepareRibbonTab(); - } + container?.PrepareRibbonTab(); } /// /// Gets called when items change on this itemscontrol. @@ -1279,10 +1270,7 @@ private static void OnIsDropDownOpenChanged(DependencyObject sender, DependencyP if (selectedTab != null) { RibbonTabAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(selectedTab) as RibbonTabAutomationPeer; - if (peer != null) - { - peer.RaiseTabExpandCollapseAutomationEvent((bool)e.OldValue, (bool)e.NewValue); - } + peer?.RaiseTabExpandCollapseAutomationEvent((bool)e.OldValue, (bool)e.NewValue); } } @@ -1338,10 +1326,7 @@ private static void OnIsMinimizedChanged(DependencyObject sender, DependencyProp // Raise UI Automation Events RibbonAutomationPeer peer = UIElementAutomationPeer.FromElement(ribbon) as RibbonAutomationPeer; - if (peer != null) - { - peer.RaiseExpandCollapseAutomationEvent(!(bool)e.OldValue, !(bool)e.NewValue); - } + peer?.RaiseExpandCollapseAutomationEvent(!(bool)e.OldValue, !(bool)e.NewValue); } @@ -1489,10 +1474,7 @@ private static void OnContextualTabGroupsSourceChanged(object sender, Dependency private static void OnNotifyContextualTabGroupPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Ribbon ribbon = (Ribbon)d; - if (ribbon.ContextualTabGroupItemsControl != null) - { - ribbon.ContextualTabGroupItemsControl.NotifyPropertyChanged(e); - } + ribbon.ContextualTabGroupItemsControl?.NotifyPropertyChanged(e); } private static void OnNotifyTabHeaderPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -1502,10 +1484,7 @@ private static void OnNotifyTabHeaderPropertyChanged(DependencyObject d, Depende for (int i = 0; i < itemCount; i++) { RibbonTab ribbonTab = ribbon.ItemContainerGenerator.ContainerFromIndex(i) as RibbonTab; - if (ribbonTab != null) - { - ribbonTab.NotifyPropertyChanged(e); - } + ribbonTab?.NotifyPropertyChanged(e); } } @@ -1713,19 +1692,13 @@ private static void OnBorderBrushChanged(DependencyObject d, DependencyPropertyC if (ribbon._tabHeaderItemsControl != null) { RibbonTabHeadersPanel tabHeadersPanel = ribbon._tabHeaderItemsControl.InternalItemsHost as RibbonTabHeadersPanel; - if (tabHeadersPanel != null) - { - tabHeadersPanel.OnNotifyRibbonBorderBrushChanged(); - } + tabHeadersPanel?.OnNotifyRibbonBorderBrushChanged(); } RibbonContextualTabGroupItemsControl contextualItemsControl = ribbon.ContextualTabGroupItemsControl; if (contextualItemsControl != null) { RibbonContextualTabGroupsPanel contextualTabHeadersPanel = contextualItemsControl.InternalItemsHost as RibbonContextualTabGroupsPanel; - if (contextualTabHeadersPanel != null) - { - contextualTabHeadersPanel.OnNotifyRibbonBorderBrushChanged(); - } + contextualTabHeadersPanel?.OnNotifyRibbonBorderBrushChanged(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonComboBox.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonComboBox.cs index 987a8d04243..7b91f6af1cc 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonComboBox.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonComboBox.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -123,8 +123,7 @@ private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedE RibbonComboBoxAutomationPeer peer = UIElementAutomationPeer.FromElement(cb) as RibbonComboBoxAutomationPeer; // Raise the propetyChangeEvent for Value if Automation Peer exist, the new Value must // be the one in SelctionBoxItem(selected value is the one user will care about) - if (peer != null) - peer.RaiseValuePropertyChangedEvent((string)e.OldValue, (string)e.NewValue); + peer?.RaiseValuePropertyChangedEvent((string)e.OldValue, (string)e.NewValue); cb.TextUpdated((string)e.NewValue, false); @@ -885,15 +884,12 @@ internal override void OnIsDropDownOpenChanged(DependencyPropertyChangedEventArg Dispatcher.BeginInvoke((Action)delegate() { - if (_firstGallery != null) - { - // Scroll the highlighted item into view. Note that we need to do the - // scroll in a Dispatcher operation because the scroll operation wont - // succeed until the Popup contents are Loaded and connected to a - // PresentationSource. We need to allow time for that to happen. + // Scroll the highlighted item into view. Note that we need to do the + // scroll in a Dispatcher operation because the scroll operation wont + // succeed until the Popup contents are Loaded and connected to a + // PresentationSource. We need to allow time for that to happen. - _firstGallery.ScrollIntoView(_firstGallery.HighlightedItem); - } + _firstGallery?.ScrollIntoView(_firstGallery.HighlightedItem); }, DispatcherPriority.Render); } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonContentPresenter.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonContentPresenter.cs index 7a8e356a9e5..0a6c3f0f8e9 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonContentPresenter.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonContentPresenter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -122,11 +122,8 @@ protected override void OnTemplateChanged(DataTemplate oldTemplate, DataTemplate if (oldTemplate != null) { RibbonHelper.ClearPseudoInheritedProperties(_templateRoot); - if (_templateRoot != null) - { - // Clearing the Ribbon property value which was set earlier. - _templateRoot.ClearValue(RibbonControlService.RibbonPropertyKey); - } + // Clearing the Ribbon property value which was set earlier. + _templateRoot?.ClearValue(RibbonControlService.RibbonPropertyKey); _templateRoot = null; } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonContextualTabGroupItemsControl.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonContextualTabGroupItemsControl.cs index 06c758bc785..cd34ebb61e2 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonContextualTabGroupItemsControl.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonContextualTabGroupItemsControl.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -152,20 +152,14 @@ protected override void PrepareContainerForItemOverride(DependencyObject element { base.PrepareContainerForItemOverride(element, item); RibbonContextualTabGroup tabGroupHeader = element as RibbonContextualTabGroup; - if (tabGroupHeader != null) - { - tabGroupHeader.PrepareTabGroupHeader(item, ItemTemplate, ItemTemplateSelector, ItemStringFormat); - } + tabGroupHeader?.PrepareTabGroupHeader(item, ItemTemplate, ItemTemplateSelector, ItemStringFormat); } protected override void ClearContainerForItemOverride(DependencyObject element, object item) { base.ClearContainerForItemOverride(element, item); RibbonContextualTabGroup tabGroupHeader = element as RibbonContextualTabGroup; - if (tabGroupHeader != null) - { - tabGroupHeader.ClearTabGroupHeader(); - } + tabGroupHeader?.ClearTabGroupHeader(); } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControl.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControl.cs index 38dde887cda..1e52c717d51 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControl.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControl.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -222,7 +222,7 @@ internal bool HostsRibbonGroup() internal UIElement ContentChild { - get { return _partContentPresenter != null ? _partContentPresenter.ContentChild : null; } + get { return _partContentPresenter?.ContentChild; } } internal bool ChildHasLargeImage diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlService.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlService.cs index e93badbab93..8c3ef87a984 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlService.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlService.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -667,10 +667,7 @@ private static void OnDefaultControlSizeDefinitionChanged(DependencyObject d, De if (ribbonGroupItemsPanel != null) { RibbonGroup ribbonGroup = TreeHelper.FindVisualAncestor(ribbonGroupItemsPanel); - if (ribbonGroup != null) - { - ribbonGroup.UpdateGroupSizeDefinitionsAsync(); - } + ribbonGroup?.UpdateGroupSizeDefinitionsAsync(); } } @@ -706,10 +703,7 @@ private static void UpdateDefaultControlSizeDefinition(DependencyObject d) if (RibbonControlService.GetIsInControlGroup(d)) { RibbonControlGroup controlGroup = TreeHelper.FindVisualAncestor(d); - if (controlGroup != null) - { - controlGroup.CoerceValue(DefaultControlSizeDefinitionProperty); - } + controlGroup?.CoerceValue(DefaultControlSizeDefinitionProperty); } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGallery.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGallery.cs index 5bbcc7808c8..a8c21693eff 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGallery.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGallery.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -2531,10 +2531,7 @@ private static void OnNotifyGalleryItemTemplateOrStylePropertyChanged(Dependency { RibbonGalleryCategory category = (RibbonGalleryCategory)gallery.ItemContainerGenerator.ContainerFromIndex(index); - if (category != null) - { - category.NotifyPropertyChanged(e); - } + category?.NotifyPropertyChanged(e); } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGalleryCategory.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGalleryCategory.cs index 9c1c3cb6e85..dfca88a132d 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGalleryCategory.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGalleryCategory.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -221,10 +221,7 @@ private static void OnNotifyPropertyChanged(DependencyObject d, DependencyProper if (e.Property == MinColumnCountProperty || e.Property == MaxColumnCountProperty || e.Property == IsSharedColumnSizeScopeProperty || e.Property == ColumnsStretchToFillProperty) { RibbonGallery gallery = galleryCategory.RibbonGallery; - if (gallery != null) - { - gallery.InvalidateMeasureOnAllCategoriesPanel(); - } + gallery?.InvalidateMeasureOnAllCategoriesPanel(); } } internal void NotifyPropertyChanged(DependencyPropertyChangedEventArgs e) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGalleryItem.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGalleryItem.cs index bad10a59d5d..92d33a859eb 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGalleryItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGalleryItem.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -63,7 +63,7 @@ internal RibbonGallery RibbonGallery { get { - return RibbonGalleryCategory != null ? RibbonGalleryCategory.RibbonGallery : null; + return RibbonGalleryCategory?.RibbonGallery; } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGroup.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGroup.cs index 8600c44dd1b..3ab27a7dd7a 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGroup.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonGroup.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -206,10 +206,7 @@ protected override void OnRenderSizeChanged(SizeChangedInfo info) if (info.WidthChanged) { RibbonGroupsPanel groupsPanel = VisualTreeHelper.GetParent(this) as RibbonGroupsPanel; - if (groupsPanel != null) - { - groupsPanel.OnChildGroupRenderSizeChanged(this, info.PreviousSize.Width); - } + groupsPanel?.OnChildGroupRenderSizeChanged(this, info.PreviousSize.Width); } } @@ -635,10 +632,7 @@ private static void OnIsDropDownOpenChanged(DependencyObject sender, DependencyP RibbonHelper.SetContentAsToolTip(group, group.VisualChild, group.Header, (group.IsCollapsed && !group.IsDropDownOpen)); RibbonGroupAutomationPeer peer = UIElementAutomationPeer.FromElement(group) as RibbonGroupAutomationPeer; - if (peer != null) - { - peer.RaiseExpandCollapseAutomationEvent((bool)e.OldValue, (bool)e.NewValue); - } + peer?.RaiseExpandCollapseAutomationEvent((bool)e.OldValue, (bool)e.NewValue); } private static object CoerceIsDropDownOpen(DependencyObject d, object baseValue) @@ -996,10 +990,7 @@ private void UpdateGroupSizeDefinitionsCallback() SetAppropriatePresenterVisibility(GroupSizeDefinitions[_sizeDefinitionIndex] is RibbonGroupSizeDefinition ? Visibility.Visible : Visibility.Collapsed); RibbonGroupsPanel panel = TreeHelper.FindVisualAncestor(this); - if (panel != null) - { - panel.InvalidateCachedMeasure(); - } + panel?.InvalidateCachedMeasure(); } GroupSizeUpdatePending = false; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonHelper.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonHelper.cs index 58016862e48..a2e8d5d4c46 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -954,10 +954,7 @@ internal static void AddHandler(DependencyObject element, RoutedEvent routedEven else { UIElement3D uiElement3D = element as UIElement3D; - if (uiElement3D != null) - { - uiElement3D.AddHandler(routedEvent, handler); - } + uiElement3D?.AddHandler(routedEvent, handler); } } } @@ -982,10 +979,7 @@ internal static void RemoveHandler(DependencyObject element, RoutedEvent routedE else { UIElement3D uiElement3D = element as UIElement3D; - if (uiElement3D != null) - { - uiElement3D.RemoveHandler(routedEvent, handler); - } + uiElement3D?.RemoveHandler(routedEvent, handler); } } } @@ -1142,10 +1136,7 @@ internal static void HandleClickThrough( { source = element; } - if (source != null) - { - source.RaiseEvent(new RibbonDismissPopupEventArgs(RibbonDismissPopupMode.MousePhysicallyNotOver)); - } + source?.RaiseEvent(new RibbonDismissPopupEventArgs(RibbonDismissPopupMode.MousePhysicallyNotOver)); } } } @@ -1259,10 +1250,7 @@ internal static void HandleDropDownKeyDown( { settor(false); e.Handled = true; - if (targetFocusOnFalse != null) - { - targetFocusOnFalse.Focus(); - } + targetFocusOnFalse?.Focus(); } } break; @@ -1290,24 +1278,18 @@ internal static void HandleDropDownKeyDown( { settor(false); e.Handled = true; - if (targetFocusOnFalse != null) - { - targetFocusOnFalse.Focus(); - } + targetFocusOnFalse?.Focus(); } else { settor(true); - if (targetFocusContainerOnTrue != null) - { - targetFocusContainerOnTrue.Dispatcher.BeginInvoke( + targetFocusContainerOnTrue?.Dispatcher.BeginInvoke( (Action)delegate() { targetFocusContainerOnTrue.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)); }, DispatcherPriority.Input, null); - } e.Handled = true; } @@ -1322,7 +1304,7 @@ internal static void HandleDropDownKeyDown( public static UIElement TryGetChild(this Popup popup) { - return (popup == null ? null : popup.Child); + return (popup?.Child); } public static bool IsCaptureInSubtree(UIElement element) @@ -1391,10 +1373,7 @@ public static void InitializeStarLayoutManager(DependencyObject starLayoutProvid { if (starLayoutManager != iContainsStarLayoutManager.StarLayoutManager) { - if (iContainsStarLayoutManager.StarLayoutManager != null) - { - iContainsStarLayoutManager.StarLayoutManager.UnregisterStarLayoutProvider(iProvideStarLayoutInfoBase); - } + iContainsStarLayoutManager.StarLayoutManager?.UnregisterStarLayoutProvider(iProvideStarLayoutInfoBase); starLayoutManager.RegisterStarLayoutProvider(iProvideStarLayoutInfoBase); iContainsStarLayoutManager.StarLayoutManager = starLayoutManager; } @@ -1410,10 +1389,7 @@ public static void InitializeStarLayoutManager(DependencyObject starLayoutProvid // will already be dirty for measure. UIElement managerElement = starLayoutManager as UIElement; - if (managerElement != null) - { - managerElement.InvalidateMeasure(); - } + managerElement?.InvalidateMeasure(); } } } @@ -2896,19 +2872,16 @@ public static void SetDropDownHeight(FrameworkElement itemsPresenter, bool hasGa internal static void InvalidateScrollBarVisibility(ScrollViewer submenuScrollViewer) { - if (submenuScrollViewer != null) - { - // The scroll viewer needs to re-evaluate the visibility of the scrollbars - // and that happens in its MeasureOverride call. Also note that we need to - // make this invalidate call async because we may already be within a - // ScrollViewer measure pass, by which we would miss the boat. + // The scroll viewer needs to re-evaluate the visibility of the scrollbars + // and that happens in its MeasureOverride call. Also note that we need to + // make this invalidate call async because we may already be within a + // ScrollViewer measure pass, by which we would miss the boat. - submenuScrollViewer.Dispatcher.BeginInvoke((Action)delegate() - { - submenuScrollViewer.InvalidateMeasure(); - }, - DispatcherPriority.Render); - } + submenuScrollViewer?.Dispatcher.BeginInvoke((Action)delegate () + { + submenuScrollViewer.InvalidateMeasure(); + }, + DispatcherPriority.Render); } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuButton.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuButton.cs index 62556477efe..e4051b179c8 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuButton.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuButton.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -1045,10 +1045,7 @@ internal bool ResizePopupInternal(double newWidth, double newHeight) internal void BringIndexIntoView(int index) { - if (_itemsHost != null) - { - _itemsHost.BringIndexIntoViewInternal(index); - } + _itemsHost?.BringIndexIntoViewInternal(index); } private void OnDropDownOpened(EventArgs e) @@ -1127,10 +1124,7 @@ internal virtual void OnIsDropDownOpenChanged(DependencyPropertyChangedEventArgs // Raise UI Automation Events RibbonMenuButtonAutomationPeer peer = UIElementAutomationPeer.FromElement(this) as RibbonMenuButtonAutomationPeer; - if (peer != null) - { - peer.RaiseExpandCollapseAutomationEvent(!(bool)e.OldValue, !(bool)e.NewValue); - } + peer?.RaiseExpandCollapseAutomationEvent(!(bool)e.OldValue, !(bool)e.NewValue); } private static object CoerceIsDropDownOpen(DependencyObject d, object baseValue) @@ -1492,10 +1486,7 @@ protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChanged // ...call PopMenuMode. MethodInfo method = type.GetMethod("PopMenuMode", BindingFlags.NonPublic | BindingFlags.Instance); Debug.Assert(method != null); - if (method != null) - { - method.Invoke(this, null); - } + method?.Invoke(this, null); } } } @@ -1665,7 +1656,7 @@ protected virtual void OnActivatingKeyTip(ActivatingKeyTipEventArgs e) { if (e.OriginalSource == this) { - RibbonHelper.SetKeyTipPlacementForButton(this, e, _partToggleButton == null ? null : _partToggleButton.Image); + RibbonHelper.SetKeyTipPlacementForButton(this, e, _partToggleButton?.Image); } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuItem.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuItem.cs index ab5cc1d646f..58f8e6eb2da 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuItem.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -723,10 +723,7 @@ protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e) if (IsKeyboardFocusWithin) { ItemsControl parent = ItemsControl.ItemsControlFromItemContainer(this); - if (parent != null) - { - parent.Focus(); - } + parent?.Focus(); } } @@ -1229,10 +1226,7 @@ private void CloseSubmenu() internal void BringIndexIntoView(int index) { - if (_itemsHost != null) - { - _itemsHost.BringIndexIntoViewInternal(index); - } + _itemsHost?.BringIndexIntoViewInternal(index); } private static bool IsContainerFocusable(FrameworkElement container) @@ -1243,10 +1237,7 @@ private static bool IsContainerFocusable(FrameworkElement container) private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonMenuItemAutomationPeer peer = UIElementAutomationPeer.FromElement((RibbonMenuItem)d) as RibbonMenuItemAutomationPeer; - if (peer != null) - { - peer.RaiseToggleStatePropertyChangedEvent((bool)e.OldValue, (bool)e.NewValue); - } + peer?.RaiseToggleStatePropertyChangedEvent((bool)e.OldValue, (bool)e.NewValue); } private static void OnIsSubmenuOpenChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) @@ -1300,10 +1291,7 @@ private static void OnIsSubmenuOpenChanged(DependencyObject sender, DependencyPr menuItem.RibbonCurrentSelection = null; RibbonMenuItemAutomationPeer peer = UIElementAutomationPeer.FromElement(menuItem) as RibbonMenuItemAutomationPeer; - if (peer != null) - { - peer.RaiseExpandCollapseAutomationEvent((bool)e.OldValue, (bool)e.NewValue); - } + peer?.RaiseExpandCollapseAutomationEvent((bool)e.OldValue, (bool)e.NewValue); } private object UpdateDropDownPosition(object arg) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonQuickAccessToolBar.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonQuickAccessToolBar.cs index e1ba308c390..4cf819f776a 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonQuickAccessToolBar.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonQuickAccessToolBar.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -187,10 +187,7 @@ private static void OnIsOverflowOpenChanged(DependencyObject sender, DependencyP // Raise UI Automation Events RibbonQuickAccessToolBarAutomationPeer peer = UIElementAutomationPeer.FromElement(qat) as RibbonQuickAccessToolBarAutomationPeer; - if (peer != null) - { - peer.RaiseExpandCollapseAutomationEvent(!(bool)e.OldValue, !(bool)e.NewValue); - } + peer?.RaiseExpandCollapseAutomationEvent(!(bool)e.OldValue, !(bool)e.NewValue); } private static object OnCoerceIsOverflowOpen(DependencyObject d, object baseValue) @@ -291,15 +288,9 @@ public override void OnApplyTemplate() { base.OnApplyTemplate(); - if (_mainPanel != null) - { - _mainPanel.Children.Clear(); - } + _mainPanel?.Children.Clear(); - if (_overflowPanel != null) - { - _overflowPanel.Children.Clear(); - } + _overflowPanel?.Children.Clear(); _mainPanel = GetTemplateChild(MainPanelTemplatePartName) as RibbonQuickAccessToolBarPanel; _overflowPanel = GetTemplateChild(OverflowPanelTemplatePartName) as RibbonQuickAccessToolBarOverflowPanel; @@ -330,10 +321,7 @@ private void InvalidateLayout() InvalidateMeasure(); RibbonQuickAccessToolBarPanel toolBarPanel = this.MainPanel; - if (toolBarPanel != null) - { - toolBarPanel.InvalidateMeasure(); - } + toolBarPanel?.InvalidateMeasure(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonSplitButton.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonSplitButton.cs index bdbabf0a27b..c0cf3564464 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonSplitButton.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonSplitButton.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -227,10 +227,7 @@ public ImageSource DropDownToolTipFooterImageSource private static void OnDropDownToolTipPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonSplitButton splitButton = (RibbonSplitButton)d; - if (splitButton.PartToggleButton != null) - { - splitButton.PartToggleButton.CoerceValue(FrameworkElement.ToolTipProperty); - } + splitButton.PartToggleButton?.CoerceValue(FrameworkElement.ToolTipProperty); } #endregion @@ -401,10 +398,7 @@ private void OnHeaderClicked(object sender, RoutedEventArgs e) if (!IsCheckable && AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { RibbonSplitButtonAutomationPeer peer = UIElementAutomationPeer.FromElement(this) as RibbonSplitButtonAutomationPeer; - if (peer != null) - { - peer.RaiseInvokeAutomationEvent(); - } + peer?.RaiseInvokeAutomationEvent(); } } @@ -414,10 +408,7 @@ private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyCha if (splitButton.IsCheckable) { RibbonSplitButtonAutomationPeer peer = UIElementAutomationPeer.FromElement(splitButton) as RibbonSplitButtonAutomationPeer; - if (peer != null) - { - peer.RaiseToggleStatePropertyChangedEvent((bool)e.OldValue, (bool)e.NewValue); - } + peer?.RaiseToggleStatePropertyChangedEvent((bool)e.OldValue, (bool)e.NewValue); } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonSplitMenuItem.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonSplitMenuItem.cs index cade4dd464c..a9fbc3e5465 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonSplitMenuItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonSplitMenuItem.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -145,10 +145,7 @@ public ImageSource DropDownToolTipFooterImageSource private static void OnDropDownToolTipPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonSplitMenuItem splitMenuItem = (RibbonSplitMenuItem)d; - if (splitMenuItem._partArrowButton != null) - { - splitMenuItem._partArrowButton.CoerceValue(FrameworkElement.ToolTipProperty); - } + splitMenuItem._partArrowButton?.CoerceValue(FrameworkElement.ToolTipProperty); } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTab.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTab.cs index cce47b68fcd..0746a6ae3f0 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTab.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTab.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -284,20 +284,14 @@ protected override void PrepareContainerForItemOverride(DependencyObject element } RibbonGroup ribbonGroup = element as RibbonGroup; - if (ribbonGroup != null) - { - ribbonGroup.PrepareRibbonGroup(); - } + ribbonGroup?.PrepareRibbonGroup(); } protected override void ClearContainerForItemOverride(DependencyObject element, object item) { base.ClearContainerForItemOverride(element, item); RibbonGroup ribbonGroup = element as RibbonGroup; - if (ribbonGroup != null) - { - ribbonGroup.ClearRibbonGroup(); - } + ribbonGroup?.ClearRibbonGroup(); } /// @@ -613,10 +607,7 @@ internal void PrepareRibbonTab() CoerceValue(VisibilityProperty); RibbonTabHeader tabHeader = RibbonTabHeader; - if (tabHeader != null) - { - tabHeader.InitializeTransferProperties(); - } + tabHeader?.InitializeTransferProperties(); } internal void NotifyPropertyChanged(DependencyPropertyChangedEventArgs e) @@ -673,10 +664,7 @@ private static object CoerceVisibility(DependencyObject d, object value) private static void OnVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { RibbonTab tab = (RibbonTab)sender; - if (tab.RibbonTabHeader != null) - { - tab.RibbonTabHeader.CoerceValue(VisibilityProperty); - } + tab.RibbonTabHeader?.CoerceValue(VisibilityProperty); // If the selected tab goes from visible to no longer visible, then reset the Ribbon's selected tab. Ribbon ribbon = tab.Ribbon; @@ -696,10 +684,7 @@ private static void OnHeaderChanged(DependencyObject d, DependencyPropertyChange { RibbonTab tab = (RibbonTab)d; Ribbon ribbon = tab.Ribbon; - if (ribbon != null) - { - ribbon.NotifyTabHeaderChanged(); - } + ribbon?.NotifyTabHeaderChanged(); OnNotifyHeaderPropertyChanged(d, e); } @@ -718,20 +703,14 @@ private static void OnIsSelectedChanged(DependencyObject sender, DependencyPrope ribbonTab.OnUnselected(new RoutedEventArgs(Selector.UnselectedEvent, ribbonTab)); } RibbonTabHeader header = ribbonTab.RibbonTabHeader; - if (header != null) - { - header.CoerceValue(RibbonTabHeader.IsRibbonTabSelectedProperty); - } + header?.CoerceValue(RibbonTabHeader.IsRibbonTabSelectedProperty); // Raise UI automation events on this RibbonTab if ( AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) || AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { RibbonTabAutomationPeer peer = RibbonTabAutomationPeer.CreatePeerForElement(ribbonTab) as RibbonTabAutomationPeer; - if (peer != null) - { - peer.RaiseTabSelectionEvents(); - } + peer?.RaiseTabSelectionEvents(); } } @@ -742,10 +721,7 @@ private static void OnIsEnabledChanged(DependencyObject sender, DependencyProper { RibbonTab ribbonTab = (RibbonTab)sender; RibbonTabHeader header = ribbonTab.RibbonTabHeader; - if (header != null) - { - header.CoerceValue(RibbonTabHeader.IsEnabledProperty); - } + header?.CoerceValue(RibbonTabHeader.IsEnabledProperty); } /// @@ -799,10 +775,7 @@ private static void OnNotifyHeaderPropertyChanged(DependencyObject d, Dependency RibbonTab tab = (RibbonTab)d; tab.NotifyPropertyChanged(e); RibbonTabHeader tabHeader = tab.RibbonTabHeader; - if (tabHeader != null) - { - tabHeader.NotifyPropertyChanged(e); - } + tabHeader?.NotifyPropertyChanged(e); } private static object CoerceHeaderStyle(DependencyObject d, object baseValue) @@ -842,10 +815,7 @@ private static void OnKeyTipChanged(DependencyObject d, DependencyPropertyChange { RibbonTab tab = (RibbonTab)d; RibbonTabHeader tabHeader = tab.RibbonTabHeader; - if (tabHeader != null) - { - tabHeader.CoerceValue(KeyTipService.KeyTipProperty); - } + tabHeader?.CoerceValue(KeyTipService.KeyTipProperty); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTabHeader.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTabHeader.cs index d86627c693c..0f8f33226e8 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTabHeader.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTabHeader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -522,10 +522,7 @@ private static object CoerceVisibility(DependencyObject d, object baseValue) private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { Panel parentPanel = VisualTreeHelper.GetParent(this) as Panel; - if (parentPanel != null) - { - parentPanel.InvalidateMeasure(); - } + parentPanel?.InvalidateMeasure(); } private static void OnIsRibbonTabSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTabHeaderItemsControl.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTabHeaderItemsControl.cs index 6a7ecb12f3f..bb1fb4f05b1 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTabHeaderItemsControl.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonTabHeaderItemsControl.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -105,10 +105,7 @@ protected override void PrepareContainerForItemOverride(DependencyObject element { base.PrepareContainerForItemOverride(element, item); RibbonTabHeader header = element as RibbonTabHeader; - if (header != null) - { - header.PrepareRibbonTabHeader(); - } + header?.PrepareRibbonTabHeader(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/TextSearchInternal.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/TextSearchInternal.cs index eb723edc9a4..deb144264a5 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/TextSearchInternal.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/TextSearchInternal.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -711,10 +711,7 @@ private void ResetState() _charsEntered.Clear(); } - if(_timeoutTimer != null) - { - _timeoutTimer.Stop(); - } + _timeoutTimer?.Stop(); _timeoutTimer = null; } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Input/CommandHelpers.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Input/CommandHelpers.cs index 259762d329c..cba46e1a29f 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Input/CommandHelpers.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Input/CommandHelpers.cs @@ -53,17 +53,11 @@ internal static void InvokeCommandSource(object parameter, object previewParamet { case CommandOperation.Preview: previewCommand = command as IPreviewCommand; - if (previewCommand != null) - { - previewCommand.Preview(previewParameter); - } + previewCommand?.Preview(previewParameter); break; case CommandOperation.CancelPreview: previewCommand = command as IPreviewCommand; - if (previewCommand != null) - { - previewCommand.CancelPreview(); - } + previewCommand?.CancelPreview(); break; case CommandOperation.Execute: command.Execute(parameter); diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs index 938d28501f1..b0029b2677f 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs @@ -984,18 +984,9 @@ private bool Process(Int64 timestamp, bool forceCompleted) { case ProcessorState.NotInitialized: // Check our various inertia behaviors to make sure they're in valid states - if (this.translationBehavior != null) - { - this.translationBehavior.CheckValid(); - } - if (this.expansionBehavior != null) - { - this.expansionBehavior.CheckValid(); - } - if (this.rotationBehavior != null) - { - this.rotationBehavior.CheckValid(); - } + this.translationBehavior?.CheckValid(); + this.expansionBehavior?.CheckValid(); + this.rotationBehavior?.CheckValid(); // verify if initialTimestamp is initialized and set it to the current timestamp if not if (this.previousTimestamp != this.initialTimestamp) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs index 63f7fd5987d..0b091b053eb 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs @@ -150,10 +150,7 @@ public void CompleteManipulation(Int64 timestamp) } OnCompleteManipulation(timestamp); - if (this.manipulatorStates != null) - { - this.manipulatorStates.Clear(); - } + this.manipulatorStates?.Clear(); } #endregion Public Methods @@ -310,10 +307,7 @@ private void ExtractAndUpdateManipulators( { foreach (Manipulator2D manipulator in manipulators) { - if (removedManipulatorIds != null) - { - removedManipulatorIds.Remove(manipulator.Id); - } + removedManipulatorIds?.Remove(manipulator.Id); currentManipulatorCount++; ManipulatorState state; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs index 18782510e80..ec04c9f92c2 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs @@ -518,7 +518,7 @@ public XamlType ParentType public XamlType GrandParentType { - get { return (_stack.PreviousPreviousFrame != null) ? _stack.PreviousPreviousFrame.XamlType : null; } + get { return _stack.PreviousPreviousFrame?.XamlType; } } public XamlMember CurrentProperty @@ -550,7 +550,7 @@ public object ParentInstance public object GrandParentInstance { - get { return (_stack.PreviousPreviousFrame != null) ? _stack.PreviousPreviousFrame.Instance : null; } + get { return _stack.PreviousPreviousFrame?.Instance; } } public object CurrentCollection @@ -649,7 +649,7 @@ public string ParentInstanceRegisteredName // Used only for BeginInitHandler, in place of BaseUri. public Uri SourceBamlUri { - get { return _settings != null ? _settings.SourceBamlUri : null; } + get { return _settings?.SourceBamlUri; } } // This specifically stores the start line number for a start object for consistency diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/XamlCommonFrame.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/XamlCommonFrame.cs index c2ca6af790e..eee9246fd41 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/XamlCommonFrame.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/XamlCommonFrame.cs @@ -41,10 +41,7 @@ public override void Reset() { XamlType = null; Member = null; - if (_namespaces != null) - { - _namespaces.Clear(); - } + _namespaces?.Clear(); } public XamlType XamlType { get; set; } @@ -57,10 +54,7 @@ public void AddNamespace(string prefix, string xamlNs) public void SetNamespaces(Dictionary namespaces) { - if (_namespaces != null) - { - _namespaces.Clear(); - } + _namespaces?.Clear(); if (namespaces != null) { foreach (KeyValuePair ns in namespaces) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs index eba1cce1adc..5faa8d077f6 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs @@ -290,10 +290,7 @@ public void SetLineInfo(int lineNumber, int linePosition) goto case DeferringMode.TemplateDeferring; case DeferringMode.TemplateDeferring: - if (_deferredLineInfoConsumer != null) - { - _deferredLineInfoConsumer.SetLineInfo(lineNumber, linePosition); - } + _deferredLineInfoConsumer?.SetLineInfo(lineNumber, linePosition); break; default: diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs index 9cc3484467f..2a36023a836 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs @@ -92,7 +92,7 @@ void Initialize(XamlSchemaContext schemaContext, XamlSavedContext savedContext, _preferUnconvertedDictionaryKeys = settings.PreferUnconvertedDictionaryKeys; } - XAML3.INameScope rootNameScope = (settings != null) ? settings.ExternalNameScope : null; + XAML3.INameScope rootNameScope = settings?.ExternalNameScope; XamlRuntime runtime = CreateRuntime(settings, schemaContext); diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs index 94c962f0ba0..6099905f952 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs @@ -408,7 +408,7 @@ string LoadRootNamespace() { RootNamespaceAttribute rootNs = (RootNamespaceAttribute) Attribute.GetCustomAttribute(assembly, typeof(RootNamespaceAttribute)); - return (rootNs == null) ? null : rootNs.Namespace; + return rootNs?.Namespace; } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/ClrObjectRuntime.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/ClrObjectRuntime.cs index 3534d23cf4e..28454d3f843 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/ClrObjectRuntime.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/ClrObjectRuntime.cs @@ -439,10 +439,7 @@ public override void SetConnectionId(object root, int connectionId, object insta try { XAML3.IComponentConnector connector = root as XAML3.IComponentConnector; - if(connector != null) - { - connector.Connect(connectionId, instance); - } + connector?.Connect(connectionId, instance); } catch(Exception e) { diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs index e5d822a72ff..c544675cbe8 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs @@ -481,10 +481,7 @@ private IList FilterProperties(PropertyInfo[] propList, List SetMarkupExtensionHandler { - get { return _xamlType != null ? _xamlType.SetMarkupExtensionHandler : null; } + get { return _xamlType?.SetMarkupExtensionHandler; } } public EventHandler SetTypeConverterHandler { - get { return _xamlType != null ? _xamlType.SetTypeConverterHandler : null; } + get { return _xamlType?.SetTypeConverterHandler; } } public virtual void AddToCollection(object instance, object item) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlException.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlException.cs index 5c712373a1d..06a90fbf753 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlException.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlException.cs @@ -143,7 +143,7 @@ public class XamlDuplicateMemberException : XamlException public XamlDuplicateMemberException() { } public XamlDuplicateMemberException(XamlMember member, XamlType type) - : base(SR.Format(SR.DuplicateMemberSet, (member != null) ? member.Name : null, (type != null) ? type.Name : null)) + : base(SR.Format(SR.DuplicateMemberSet, member?.Name, type?.Name)) { DuplicateMember = member; ParentType = type; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs index 66e05db9496..51fcde32cef 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs @@ -730,7 +730,7 @@ protected virtual MethodInfo LookupUnderlyingGetter() return _reflector.Getter; } PropertyInfo pi = UnderlyingMember as PropertyInfo; - return (pi != null) ? pi.GetGetMethod(true) : null; + return pi?.GetGetMethod(true); } protected virtual MethodInfo LookupUnderlyingSetter() @@ -750,7 +750,7 @@ protected virtual MethodInfo LookupUnderlyingSetter() else { EventInfo ei = UnderlyingMember as EventInfo; - return (ei != null) ? ei.GetAddMethod(true) : null; + return ei?.GetAddMethod(true); } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs index f371af246eb..9e06c3bcaac 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs @@ -101,7 +101,7 @@ public override bool Read() currentXamlNode = node.XamlNode; ObjectMarkupInfo objectNode = node as ObjectMarkupInfo; - currentInstance = objectNode != null ? objectNode.Object : null; + currentInstance = objectNode?.Object; var subNodes = node.Decompose(); @@ -2452,10 +2452,7 @@ public string FindInServiceProviderTable(object value) { string result = null; - if (serviceProviderTable != null) - { - serviceProviderTable.TryGetValue(value, out result); - } + serviceProviderTable?.TryGetValue(value, out result); // this search is not recursive, because only names requested in the current // namescope are meaningful references. @@ -3195,7 +3192,7 @@ internal static class TypeConverterExtensions { public static TConverter GetConverterInstance(XamlValueConverter converter) where TConverter : class { - return (converter == null) ? null : converter.ConverterInstance; + return converter?.ConverterInstance; } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs index f3f74d0b919..c125a4d8772 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs @@ -782,10 +782,7 @@ private static void CleanupCollectedAssemblies(object schemaContextWeakRef) { WeakReference weakRef = (WeakReference)schemaContextWeakRef; XamlSchemaContext schemaContext = weakRef.Target as XamlSchemaContext; - if (schemaContext != null) - { - schemaContext.CleanupCollectedAssemblies(); - } + schemaContext?.CleanupCollectedAssemblies(); } // Iterate through any weak references we hold to dynamic assemblies, cleaning up references @@ -1351,10 +1348,7 @@ public AssemblyLoadHandler(XamlSchemaContext schemaContext) private void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args) { XamlSchemaContext schemaContext = (XamlSchemaContext)schemaContextRef.Target; - if (schemaContext != null) - { - schemaContext.SchemaContextAssemblyLoadEventHandler(sender, args); - } + schemaContext?.SchemaContextAssemblyLoadEventHandler(sender, args); } public void Hook() diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs index 98cbc6a2395..3549fba748f 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs @@ -980,7 +980,7 @@ protected virtual IEnumerable LookupAllAttachableMembers() { if (UnderlyingType == null) { - return (BaseType != null) ? BaseType.GetAllAttachableMembers() : null; + return BaseType?.GetAllAttachableMembers(); } EnsureReflector(); return _reflector.LookupAllAttachableMembers(SchemaContext); @@ -990,7 +990,7 @@ protected virtual IEnumerable LookupAllMembers() { if (UnderlyingType == null) { - return (BaseType != null) ? BaseType.GetAllMembers() : null; + return BaseType?.GetAllMembers(); } EnsureReflector(); @@ -1058,7 +1058,7 @@ protected virtual XamlMember LookupAttachableMember(string name) { if (UnderlyingType == null) { - return (BaseType != null) ? BaseType.GetAttachableMember(name) : null; + return BaseType?.GetAttachableMember(name); } EnsureReflector(); diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ButtonChrome.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ButtonChrome.cs index 11f183933e7..091d067446e 100644 --- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ButtonChrome.cs +++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ButtonChrome.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -446,10 +446,7 @@ protected override Size ArrangeOverride(Size finalSize) childArrangeRect.Y = (finalSize.Height - childArrangeRect.Height) * 0.5; UIElement child = Child; - if (child != null) - { - child.Arrange(childArrangeRect); - } + child?.Arrange(childArrangeRect); return finalSize; } diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ListBoxChrome.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ListBoxChrome.cs index 134c562a568..3df1fb27976 100644 --- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ListBoxChrome.cs +++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ListBoxChrome.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -286,10 +286,7 @@ protected override Size ArrangeOverride(Size finalSize) childArrangeRect.Height = finalSize.Height - borderY; } - if (Child != null) - { - Child.Arrange(childArrangeRect); - } + Child?.Arrange(childArrangeRect); return finalSize; } diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ButtonChrome.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ButtonChrome.cs index 11f183933e7..091d067446e 100644 --- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ButtonChrome.cs +++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ButtonChrome.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -446,10 +446,7 @@ protected override Size ArrangeOverride(Size finalSize) childArrangeRect.Y = (finalSize.Height - childArrangeRect.Height) * 0.5; UIElement child = Child; - if (child != null) - { - child.Arrange(childArrangeRect); - } + child?.Arrange(childArrangeRect); return finalSize; } diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ListBoxChrome.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ListBoxChrome.cs index 134c562a568..3df1fb27976 100644 --- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ListBoxChrome.cs +++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ListBoxChrome.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -286,10 +286,7 @@ protected override Size ArrangeOverride(Size finalSize) childArrangeRect.Height = finalSize.Height - borderY; } - if (Child != null) - { - Child.Arrange(childArrangeRect); - } + Child?.Arrange(childArrangeRect); return finalSize; } diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Luna/Microsoft/Windows/Themes/ButtonChrome.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Luna/Microsoft/Windows/Themes/ButtonChrome.cs index 4e9a76cbb47..6068afca941 100644 --- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Luna/Microsoft/Windows/Themes/ButtonChrome.cs +++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Luna/Microsoft/Windows/Themes/ButtonChrome.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -367,10 +367,7 @@ protected override Size ArrangeOverride(Size finalSize) childArrangeRect.Y = (finalSize.Height - childArrangeRect.Height) * 0.5; UIElement child = Child; - if (child != null) - { - child.Arrange(childArrangeRect); - } + child?.Arrange(childArrangeRect); return finalSize; } diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Royale/Microsoft/Windows/Themes/ButtonChrome.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Royale/Microsoft/Windows/Themes/ButtonChrome.cs index db7a1a6ef48..c7942a2619b 100644 --- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Royale/Microsoft/Windows/Themes/ButtonChrome.cs +++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Royale/Microsoft/Windows/Themes/ButtonChrome.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -325,10 +325,7 @@ protected override Size ArrangeOverride(Size finalSize) childArrangeRect.Y = (finalSize.Height - childArrangeRect.Height) * 0.5; UIElement child = Child; - if (child != null) - { - child.Arrange(childArrangeRect); - } + child?.Arrange(childArrangeRect); return finalSize; } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/WinEventWrap.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/WinEventWrap.cs index 5138ce299cc..50a59eb399f 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/WinEventWrap.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/WinEventWrap.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -142,10 +142,7 @@ internal void StopListening() _hHooks[i] = IntPtr.Zero; } } - if (_qEvents != null) - { - _qEvents.Clear(); - } + _qEvents?.Clear(); _fBusy = false; } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/MSAAWinEventWrap.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/MSAAWinEventWrap.cs index cf106d62da0..3739f4abe8c 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/MSAAWinEventWrap.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/MSAAWinEventWrap.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -101,10 +101,7 @@ internal void StopListening() _hHooks[i] = IntPtr.Zero; } } - if (_qEvents != null) - { - _qEvents.Clear(); - } + _qEvents?.Clear(); _fBusy = false; } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/NonClientArea.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/NonClientArea.cs index 956b28249d4..2193ecf4401 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/NonClientArea.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/NonClientArea.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -50,10 +50,7 @@ internal override void AdviseEventAdded (AutomationEvent eventId, AutomationProp } } - if (menuProxy != null) - { - menuProxy.AdviseEventAdded(eventId, aidProps); - } + menuProxy?.AdviseEventAdded(eventId, aidProps); base.AdviseEventAdded(eventId, aidProps); } @@ -73,10 +70,7 @@ internal override void AdviseEventRemoved (AutomationEvent eventId, AutomationPr } } - if (menuProxy != null) - { - menuProxy.AdviseEventRemoved(eventId, aidProps); - } + menuProxy?.AdviseEventRemoved(eventId, aidProps); base.AdviseEventRemoved(eventId, aidProps); } @@ -650,10 +644,7 @@ private ProxySimple FindMenus(int x, int y) private static void RaiseMenuEventsOnClient(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) { ProxySimple el = WindowsMenu.CreateMenuItemFromEvent(hwnd, eventId, idChild, idObject); - if (el != null) - { - el.DispatchEvents(eventId, idProp, idObject, idChild); - } + el?.DispatchEvents(eventId, idProp, idObject, idChild); } private static void RaiseEventsOnClient(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) @@ -661,10 +652,7 @@ private static void RaiseEventsOnClient(IntPtr hwnd, int eventId, object idProp, if (Misc.GetClassName(hwnd) == "ComboLBox") { ProxySimple el = (ProxySimple)WindowsListBox.Create(hwnd, idChild); - if (el != null) - { - el.DispatchEvents(eventId, idProp, idObject, idChild); - } + el?.DispatchEvents(eventId, idProp, idObject, idChild); } } @@ -688,10 +676,7 @@ private static void RaiseEventsOnScroll(IntPtr hwnd, int eventId, object idProp, if (scrollBar != null) { ProxySimple scrollBarBit = WindowsScrollBarBits.CreateFromChildId(hwnd, scrollBar, idChild, sbFlag); - if (scrollBarBit != null) - { - scrollBarBit.DispatchEvents(eventId, idProp, idObject, idChild); - } + scrollBarBit?.DispatchEvents(eventId, idProp, idObject, idChild); } return; @@ -732,10 +717,7 @@ private static void RaiseEventsOnScroll(IntPtr hwnd, int eventId, object idProp, el = (ProxyFragment)WindowsListBox.Create(hwnd, 0); } - if (el != null) - { - el.DispatchEvents(eventId, idProp, idObject, idChild); - } + el?.DispatchEvents(eventId, idProp, idObject, idChild); } private static void RaiseEventsOnWindow(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs index 9afd74b2cb5..70f3cfdad7b 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -278,10 +278,7 @@ internal override void AdviseEventAdded(AutomationEvent eventId, AutomationPrope base.AdviseEventAdded(eventId, aidProps); // Need to also advise the edit portions of the spinner so that it can raise events. - if (_elEdit != null) - { - _elEdit.AdviseEventAdded(eventId, aidProps); - } + _elEdit?.AdviseEventAdded(eventId, aidProps); } internal override void AdviseEventRemoved(AutomationEvent eventId, AutomationProperty[] aidProps) @@ -289,10 +286,7 @@ internal override void AdviseEventRemoved(AutomationEvent eventId, AutomationPro base.AdviseEventRemoved(eventId, aidProps); // Need to also remove the advise from the edit portions of the spinner. - if (_elEdit != null) - { - _elEdit.AdviseEventRemoved(eventId, aidProps); - } + _elEdit?.AdviseEventRemoved(eventId, aidProps); } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsAltTab.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsAltTab.cs index 2ead143b8ff..669147e160a 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsAltTab.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsAltTab.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -82,10 +82,7 @@ internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int i if (idObject != NativeMethods.OBJID_VSCROLL && idObject != NativeMethods.OBJID_HSCROLL) { ProxySimple el = (ProxyHwnd) WindowsAltTab.Create(hwnd, 0); - if (el != null) - { - el.DispatchEvents(eventId, idProp, idObject, idChild); - } + el?.DispatchEvents(eventId, idProp, idObject, idChild); } } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsComboBox.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsComboBox.cs index 7796ccc0c33..32cdc99c68c 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsComboBox.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsComboBox.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -779,10 +779,7 @@ static private void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int id } - if (el != null) - { - el.DispatchEvents (eventId, idProp, idObject, idChild); - } + el?.DispatchEvents (eventId, idProp, idObject, idChild); } // Handles combo's edit portion specific events diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListBox.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListBox.cs index 4196de133dc..c71f557c15b 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListBox.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListBox.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -124,10 +124,7 @@ internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int i default : ProxySimple el = (ProxyHwnd)WindowsListBox.Create(hwnd, 0); - if (el != null) - { - el.DispatchEvents(eventId, idProp, idObject, idChild); - } + el?.DispatchEvents(eventId, idProp, idObject, idChild); break; } } @@ -507,10 +504,7 @@ private static void RaiseEventsOnClient(IntPtr hwnd, int eventId, object idProp, return; } - if (el != null) - { - el.DispatchEvents(eventId, idProp, idObject, idChild); - } + el?.DispatchEvents(eventId, idProp, idObject, idChild); } private static void RaiseEventsOnWindow(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) @@ -538,10 +532,7 @@ private static void RaiseEventsOnWindow(IntPtr hwnd, int eventId, object idProp, } } - if (el != null) - { - el.DispatchEvents(eventId, idProp, idObject, idChild); - } + el?.DispatchEvents(eventId, idProp, idObject, idChild); } #region Selection Pattern Helpers diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListView.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListView.cs index adac44a694b..ec0c9a629fc 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListView.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -140,10 +140,7 @@ internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int i default : { ProxySimple el = new WindowsListView( hwnd, null, -1 ); - if (el != null) - { - el.DispatchEvents( eventId, idProp, idObject, idChild ); - } + el?.DispatchEvents( eventId, idProp, idObject, idChild ); break; } } @@ -2002,10 +1999,7 @@ private static void RaiseEventsOnClient(IntPtr hwnd, int eventId, object idProp, el = wlv; } - if (el != null) - { - el.DispatchEvents(eventId, idProp, idObject, idChild); - } + el?.DispatchEvents(eventId, idProp, idObject, idChild); return; } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScrollBar.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScrollBar.cs index f8c10e11921..bd3450ca6fc 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScrollBar.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScrollBar.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -99,10 +99,7 @@ internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int i { // raise events for the children ProxySimple scrollBarBit = WindowsScrollBarBits.CreateFromChildId(hwnd, wtv, idChild, NativeMethods.SB_CTL); - if (scrollBarBit != null) - { - scrollBarBit.DispatchEvents(eventId, idProp, idObject, idChild); - } + scrollBarBit?.DispatchEvents(eventId, idProp, idObject, idChild); } } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsStatic.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsStatic.cs index e90bca4368b..4ca49decddd 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsStatic.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsStatic.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -111,8 +111,7 @@ internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int i WindowsStatic wtv = (WindowsStatic) Create (hwnd, 0); // If wtv is null the window handle is invalid or no longer available (or something, // Create eats the problem). - if (wtv != null) - wtv.DispatchEvents (eventId, idProp, idObject, idChild); + wtv?.DispatchEvents (eventId, idProp, idObject, idChild); } } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs index 5e95d1609f7..fc63dcf11a0 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -80,10 +80,7 @@ internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int i { // Notify the Listview that the header Change WindowsListView wlv = (WindowsListView) WindowsListView.Create (hwndParent, 0); - if (wlv != null) - { - wlv.DispatchEvents (eventId, idProp, idObject, idChild); - } + wlv?.DispatchEvents (eventId, idProp, idObject, idChild); } } } @@ -469,10 +466,7 @@ void IInvokeProvider.Invoke () } WindowsSysHeader parent = _parent as WindowsSysHeader; - if (parent != null) - { - parent.ScrollIntoView(this); - } + parent?.ScrollIntoView(this); NativeMethods.Win32Point pt; @@ -717,10 +711,7 @@ private void ClickSplitButton () } WindowsSysHeader parent = _parent as WindowsSysHeader; - if (parent != null) - { - parent.ScrollIntoView(this); - } + parent?.ScrollIntoView(this); Rect rect = XSendMessage.GetItemRect(_hwnd, NativeMethods.HDM_GETITEMDROPDOWNRECT, _item); diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTab.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTab.cs index 7771a97699d..64dfb66443d 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTab.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTab.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -108,10 +108,7 @@ internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int i el = new WindowsTab(hwnd, null, -1); break; } - if (el != null) - { - el.DispatchEvents (eventId, idProp, idObject, idChild); - } + el?.DispatchEvents (eventId, idProp, idObject, idChild); } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsToolbar.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsToolbar.cs index a350b72e595..f2e2304e783 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsToolbar.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsToolbar.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -99,10 +99,7 @@ internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int i } } // Ends up calling CreateToolbarItem which can return null - if (proxySimple != null) - { - proxySimple.DispatchEvents(eventId, idProp, idObject, idChild); - } + proxySimple?.DispatchEvents(eventId, idProp, idObject, idChild); } } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTreeView.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTreeView.cs index ecd4c045e71..bf63ede5752 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTreeView.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTreeView.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -109,10 +109,7 @@ internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int i return; } - if (el != null) - { - el.DispatchEvents (eventId, idProp, idObject, idChild); - } + el?.DispatchEvents (eventId, idProp, idObject, idChild); } #endregion Proxy Create diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs index 2e2a9886647..04c82395738 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -85,10 +85,7 @@ private static void RaiseInvokedEvent(IntPtr hwnd, int idObject, int idChild) WindowsUpDown wtv = new WindowsUpDown(hwnd, null, -1); button = wtv.CreateSpinButtonItem(SpinItem.UpArrow); } - if (button != null) - { - button.DispatchEvents(NativeMethods.EventObjectInvoke, InvokePattern.InvokedEvent, idObject, idChild); - } + button?.DispatchEvents(NativeMethods.EventObjectInvoke, InvokePattern.InvokedEvent, idObject, idChild); } // Creates a list item RawElementBase Item diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DPCustomTypeDescriptor.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DPCustomTypeDescriptor.cs index 970276ad2f7..39378b7fa7c 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DPCustomTypeDescriptor.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DPCustomTypeDescriptor.cs @@ -188,9 +188,9 @@ public PropertyDescriptorCollection GetProperties(Attribute[] attributes) } } } - else if (newDescriptors != null) + else { - newDescriptors.Add(prop); + newDescriptors?.Add(prop); } } diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs index 712c1e1f646..9363055ecd9 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs @@ -136,10 +136,7 @@ internal static int WriteByteLengthPrefixedDWordPaddedUnicodeString(BinaryWriter { strByteLen += padLength; - if (writer != null) - { - writer.Write(_paddingBuf, 0, padLength); - } + writer?.Write(_paddingBuf, 0, padLength); } } diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/NativeCompoundFileAPIs.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/NativeCompoundFileAPIs.cs index ed1a90d48b7..3ccf4be9c66 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/NativeCompoundFileAPIs.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/NativeCompoundFileAPIs.cs @@ -226,10 +226,7 @@ protected virtual void Dispose(bool disposing) // If the storage was originally opened on lockbyte implementation // we need to dispose it as well - if (_unsafeLockByteStream != null) - { - _unsafeLockByteStream.Dispose(); - } + _unsafeLockByteStream?.Dispose(); } } finally diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/SparseMemoryStream.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/SparseMemoryStream.cs index 1eee09c5430..15b97435ddf 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/SparseMemoryStream.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/SparseMemoryStream.cs @@ -404,11 +404,8 @@ protected override void Dispose(bool disposing) } // clean up isolated storage resources if in use - if (_isolatedStorageStream != null) - { - // can only rely on _isolatedStorageStream behaving correctly if we are not in our finalizer - _isolatedStorageStream.Close(); - } + // can only rely on _isolatedStorageStream behaving correctly if we are not in our finalizer + _isolatedStorageStream?.Close(); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlDigitalSignatureProcessor.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlDigitalSignatureProcessor.cs index 4e020b7d647..671fdceab2f 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlDigitalSignatureProcessor.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlDigitalSignatureProcessor.cs @@ -525,8 +525,7 @@ internal static HashAlgorithm GetHashAlgorithm(String hashAlgorithmName) if (algorithm == null && o != null) { IDisposable disposable = o as IDisposable; - if (disposable != null) - disposable.Dispose(); + disposable?.Dispose(); } return algorithm; diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/InheritanceContextHelper.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/InheritanceContextHelper.cs index 255fdb2eb33..d2b7a57358b 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/InheritanceContextHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/InheritanceContextHelper.cs @@ -23,10 +23,7 @@ internal static void ProvideContextForObject( DependencyObject context, DependencyObject newValue ) { - if (context != null) - { - context.ProvideSelfAsInheritanceContext(newValue, null); - } + context?.ProvideSelfAsInheritanceContext(newValue, null); } //-------------------------------------------------------------------- diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/ClientSession.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/ClientSession.cs index 5488c32bcae..8cd509e3cc6 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/ClientSession.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/ClientSession.cs @@ -130,10 +130,7 @@ protected virtual void Dispose(bool disposing) // Dispose call back handler try { - if (_callbackHandler != null) - { - _callbackHandler.Dispose(); - } + _callbackHandler?.Dispose(); } finally { diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/IssuanceLicense.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/IssuanceLicense.cs index e5b0754067b..9bb3278b004 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/IssuanceLicense.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/IssuanceLicense.cs @@ -694,8 +694,8 @@ private LocalizedNameDescriptionPair GetLocalizedNameDescriptionPair checked { localeId = (int)locId; } // now we can build a ContentUser - return new LocalizedNameDescriptionPair(name == null ? null : name.ToString(), - description == null ? null : description.ToString()); + return new LocalizedNameDescriptionPair(name?.ToString(), + description?.ToString()); } private Nullable> GetApplicationSpecificData(int index) @@ -752,8 +752,8 @@ private Nullable> GetApplicationSpecificData(int in Errors.ThrowOnErrorCode(hr); // build strings from the StringBuilder instances - string name = (tempName == null) ? null : tempName.ToString(); - string value = (tempValue == null) ? null : tempValue.ToString(); + string name = tempName?.ToString(); + string value = tempValue?.ToString(); KeyValuePair result = new KeyValuePair(name, value); @@ -997,11 +997,11 @@ private RevocationPoint GetRevocationPoint() RevocationPoint resultRevocationPoint = new RevocationPoint(); - resultRevocationPoint.Id = (idTemp == null) ? null : idTemp.ToString(); - resultRevocationPoint.IdType = (idTypeTemp == null) ? null : idTypeTemp.ToString(); + resultRevocationPoint.Id = idTemp?.ToString(); + resultRevocationPoint.IdType = idTypeTemp?.ToString(); resultRevocationPoint.Url = (urlTemp == null) ? null : new Uri(urlTemp.ToString()); - resultRevocationPoint.Name = (nameTemp == null) ? null : nameTemp.ToString(); - resultRevocationPoint.PublicKey = (publicKeyTemp == null) ? null : publicKeyTemp.ToString(); + resultRevocationPoint.Name = nameTemp?.ToString(); + resultRevocationPoint.PublicKey = publicKeyTemp?.ToString(); resultRevocationPoint.Frequency = frequency; return resultRevocationPoint; diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Utilities.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Utilities.cs index d790a410c9f..34999929e97 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Utilities.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Utilities.cs @@ -49,10 +49,7 @@ internal static void SafeDispose(ref T disposable) where T : IDisposable // Dispose can safely be called on an object multiple times. IDisposable t = disposable; disposable = default(T); - if (null != t) - { - t.Dispose(); - } + t?.Dispose(); } internal static void SafeRelease(ref T comObject) where T : class diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/DataSpaceManager.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/DataSpaceManager.cs index 495fc5f1fbb..da68f63b3ff 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/DataSpaceManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/DataSpaceManager.cs @@ -353,8 +353,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (_baseStream != null) - _baseStream.Close(); + _baseStream?.Close(); } } finally diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/EncryptedPackage.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/EncryptedPackage.cs index 5084d437510..6178cdc32c6 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/EncryptedPackage.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/EncryptedPackage.cs @@ -499,10 +499,7 @@ string fileName } finally { - if (root != null) - { - root.Close(); - } + root?.Close(); } return retval; @@ -556,10 +553,7 @@ Stream stream } finally { - if (root != null) - { - root.Close(); - } + root?.Close(); } return retval; @@ -576,15 +570,9 @@ public void Flush() // Since _package is only initialized when the client calls GetPackage, it might // not be set when the client calls Flush, so we have to check. // - if (_package != null) - { - _package.Flush(); - } + _package?.Flush(); - if (_packageStream != null) - { - _packageStream.Flush(); - } + _packageStream?.Flush(); Invariant.Assert(_root != null, "The envelope cannot be null"); @@ -1018,10 +1006,7 @@ bool disposing // might have opened the compound file just to look at the properties, and // never even opened the package. // - if (_package != null) - { - _package.Close(); - } + _package?.Close(); } finally { @@ -1029,10 +1014,7 @@ bool disposing try { - if (_packageStream != null) - { - _packageStream.Close(); - } + _packageStream?.Close(); } finally { @@ -1040,10 +1022,7 @@ bool disposing try { - if (_packageProperties != null) - { - _packageProperties.Dispose(); - } + _packageProperties?.Dispose(); } finally { @@ -1051,10 +1030,7 @@ bool disposing try { - if (_root != null) - { - _root.Close(); - } + _root?.Close(); } finally { diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObject.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObject.cs index 1923e998bbd..fc3ff8d3a32 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObject.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObject.cs @@ -1139,10 +1139,7 @@ internal void NotifySubPropertyChange(DependencyProperty dp) // if the target is a Freezable, call FireChanged to kick off // notifications to the Freezable's parent chain. Freezable freezable = this as Freezable; - if (freezable != null) - { - freezable.FireChanged(); - } + freezable?.FireChanged(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Freezable.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Freezable.cs index 8e53634f261..36b873bcb0d 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Freezable.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Freezable.cs @@ -548,10 +548,7 @@ private void GetChangeHandlersAndInvalidateSubProperties(ref EventStorage called DependencyObject context = SingletonContext; contextAsFreezable = context as Freezable; - if (contextAsFreezable != null) - { - contextAsFreezable.GetChangeHandlersAndInvalidateSubProperties(ref calledHandlers); - } + contextAsFreezable?.GetChangeHandlersAndInvalidateSubProperties(ref calledHandlers); if (SingletonContextProperty != null) { @@ -577,10 +574,7 @@ private void GetChangeHandlersAndInvalidateSubProperties(ref EventStorage called if (currentDO != lastDO) { contextAsFreezable = currentDO as Freezable; - if (contextAsFreezable != null) - { - contextAsFreezable.GetChangeHandlersAndInvalidateSubProperties(ref calledHandlers); - } + contextAsFreezable?.GetChangeHandlersAndInvalidateSubProperties(ref calledHandlers); lastDO = currentDO; } diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/NameScope.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/NameScope.cs index ab1e9298e01..0779e8967ba 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/NameScope.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/NameScope.cs @@ -421,10 +421,7 @@ object IEnumerator.Current void IEnumerator.Reset() { - if (_enumerator != null) - { - _enumerator.Reset(); - } + _enumerator?.Reset(); } } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/PropertyMetadata.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/PropertyMetadata.cs index dbbe971e83b..416dac4d9de 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/PropertyMetadata.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/PropertyMetadata.cs @@ -255,12 +255,9 @@ internal static void PromoteAllCachedDefaultValues(DependencyObject owner) { FrugalMapBase map = _defaultValueFactoryCache.GetValue(owner); - if (map != null) - { - // Iterate through all the items in the map (each representing a DP) - // and promote them to locally-set. - map.Iterate(null, _promotionCallback); - } + // Iterate through all the items in the map (each representing a DP) + // and promote them to locally-set. + map?.Iterate(null, _promotionCallback); } /// @@ -321,11 +318,8 @@ private static void DefaultValueCachePromotionCallback(ArrayList list, int key, { Freezable cachedDefault = value as Freezable; - if (cachedDefault != null) - { - // The only way to promote a cached default is to fire its Changed event. - cachedDefault.FireChanged(); - } + // The only way to promote a cached default is to fire its Changed event. + cachedDefault?.FireChanged(); } diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs index 6f7ccd53ba2..ea0e40a95e0 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs @@ -963,10 +963,7 @@ private void InvokeAsyncImpl(DispatcherOperation operation, CancellationToken ca operation.Completed += (s,e) => cancellationRegistration.Dispose(); } - if(hooks != null) - { - hooks.RaiseOperationPosted(this, operation); - } + hooks?.RaiseOperationPosted(this, operation); if (EventTrace.IsEnabled(EventTrace.Keyword.KeywordDispatcher | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info)) { @@ -1400,10 +1397,7 @@ private object InvokeImpl(DispatcherOperation operation, CancellationToken cance finally { ctTimeoutRegistration.Dispose(); - if (ctsTimeout != null) - { - ctsTimeout.Dispose(); - } + ctsTimeout?.Dispose(); } } @@ -1887,10 +1881,7 @@ private void ShutdownImplInSecurityContext(Object state) } } - if(operation != null) - { - operation.Abort(); - } + operation?.Abort(); } while(operation != null); // clear out the fields that could be holding onto large graphs of objects. @@ -1944,10 +1935,7 @@ internal bool SetPriority(DispatcherOperation operation, DispatcherPriority prio if (notify) { - if(hooks != null) - { - hooks.RaiseOperationPriorityChanged(this, operation); - } + hooks?.RaiseOperationPriorityChanged(this, operation); if (EventTrace.IsEnabled(EventTrace.Keyword.KeywordDispatcher | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info)) { @@ -1978,10 +1966,7 @@ internal bool Abort(DispatcherOperation operation) if (notify) { - if(hooks != null) - { - hooks.RaiseOperationAborted(this, operation); - } + hooks?.RaiseOperationAborted(this, operation); if (EventTrace.IsEnabled(EventTrace.Keyword.KeywordDispatcher | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info)) { @@ -2038,17 +2023,11 @@ private void ProcessQueue() eventlogged = true; } - if(hooks != null) - { - hooks.RaiseOperationStarted(this, op); - } + hooks?.RaiseOperationStarted(this, op); op.Invoke(); - if(hooks != null) - { - hooks.RaiseOperationCompleted(this, op); - } + hooks?.RaiseOperationCompleted(this, op); if (eventlogged) { @@ -2289,10 +2268,7 @@ private IntPtr WndProcHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, r if (idle) { - if(hooks != null) - { - hooks.RaiseDispatcherInactive(this); - } + hooks?.RaiseDispatcherInactive(this); ComponentDispatcher.RaiseIdle(); } @@ -2576,10 +2552,7 @@ internal void PromoteTimers(int currentTimeInTicks) } // Now that we are outside of the lock, promote the timer. - if(timer != null) - { - timer.Promote(); - } + timer?.Promote(); } while(timer != null); } } diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherHookEventArgs.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherHookEventArgs.cs index d63d1045ec5..db5cda82075 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherHookEventArgs.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherHookEventArgs.cs @@ -27,7 +27,7 @@ public Dispatcher Dispatcher { get { - return _operation != null ? _operation.Dispatcher : null; + return _operation?.Dispatcher; } } diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherObject.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherObject.cs index bc91d3394ed..0335a4a1537 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherObject.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherObject.cs @@ -113,10 +113,7 @@ public void VerifyAccess() // Note: a DispatcherObject that is not associated with a // dispatcher is considered to be free-threaded. - if(dispatcher != null) - { - dispatcher.VerifyAccess(); - } + dispatcher?.VerifyAccess(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs index 3dcdd440808..447bea043a0 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs @@ -597,10 +597,7 @@ private void Exit() { Continue = false; - if(_waitTimer != null) - { - _waitTimer.Dispose(); - } + _waitTimer?.Dispose(); _operation.Aborted -= new EventHandler(OnCompletedOrAborted); _operation.Completed -= new EventHandler(OnCompletedOrAborted); diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ElementHost.cs b/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ElementHost.cs index d105958d707..329136a0c03 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ElementHost.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ElementHost.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -439,10 +439,7 @@ protected override void Select(bool directed, bool forward) } else { - if (Child != null) - { - Child.Focus(); - } + Child?.Focus(); } base.Select(directed, forward); @@ -849,10 +846,7 @@ protected override void Dispose(bool disposing) SWI.InputManager.Current.PostProcessInput -= InputManager_PostProcessInput; IDisposable disposableChild = Child as IDisposable; - if (disposableChild != null) - { - disposableChild.Dispose(); - } + disposableChild?.Dispose(); } } } @@ -1027,10 +1021,7 @@ private void OnPropertyChangedImeMode(object sender, System.EventArgs e) /// the new value of the property public virtual void OnPropertyChanged(string propertyName, object value) { - if (PropertyMap != null) - { - PropertyMap.OnPropertyChanged(this, propertyName, value); - } + PropertyMap?.OnPropertyChanged(this, propertyName, value); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/WindowsFormsHost.cs b/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/WindowsFormsHost.cs index 1145de6bc4c..fa13e3a3b07 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/WindowsFormsHost.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/WindowsFormsHost.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -180,10 +180,7 @@ protected virtual Vector ScaleChild(Vector newScale) { if (newScale != _currentScale) { - if (Child != null) - { - Child.Scale(new System.Drawing.SizeF((float)(newScale.X / _currentScale.X), (float)(newScale.Y / _currentScale.Y))); - } + Child?.Scale(new System.Drawing.SizeF((float)(newScale.X / _currentScale.X), (float)(newScale.Y / _currentScale.Y))); } Vector returnScale = newScale; returnScale.X = (newScale.X == 0) ? _currentScale.X : newScale.X; @@ -485,10 +482,7 @@ protected override HandleRef BuildWindowCore(HandleRef hwndParent) // for 4.0 compat, create a Winforms.NativeWindow to swallow exceptions during WndProc if (!CoreCompatibilityPreferences.TargetsAtLeast_Desktop_V4_5) { - if (_dummyNativeWindow != null) - { - _dummyNativeWindow.Dispose(); - } + _dummyNativeWindow?.Dispose(); _dummyNativeWindow = new DummyNativeWindow(this); _dummyNativeWindow.AssignHandle(hwndParent.Handle); } @@ -512,10 +506,7 @@ protected override void DestroyWindowCore(HandleRef hwnd) //This line shouldn't be necessary since the list cleans itself, but it's good to be tidy. ApplicationInterop.ThreadWindowsFormsHostList.Remove(this); - if (HostContainerInternal != null) - { - HostContainerInternal.Dispose(); - } + HostContainerInternal?.Dispose(); } void ApplyAllProperties(object sender, RoutedEventArgs e) @@ -540,19 +531,13 @@ protected override void Dispose(bool disposing) { try { - if (_dummyNativeWindow != null) - { - _dummyNativeWindow.Dispose(); - } + _dummyNativeWindow?.Dispose(); _hostContainerInternal.Dispose(); this.Loaded -= new RoutedEventHandler(ApplyAllProperties); } finally { - if (Child != null) - { - Child.Dispose(); - } + Child?.Dispose(); } } } @@ -708,10 +693,7 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) base.OnPropertyChanged(e); // Invoke method currently set to handle this event - if (_propertyMap != null) - { - _propertyMap.OnPropertyChanged(this, e.Property.Name, e.NewValue); - } + _propertyMap?.OnPropertyChanged(this, e.Property.Name, e.NewValue); } /// @@ -1114,10 +1096,7 @@ private void CallOnParentRightToLeftChanged(Control control) { MethodInfo methodInfo = typeof(SWF.Control).GetMethod("OnParentRightToLeftChanged", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(EventArgs) }, null); Debug.Assert(methodInfo != null, "Couldn't find OnParentRightToLeftChanged method!"); - if (methodInfo != null) - { - methodInfo.Invoke(control, new object[] { EventArgs.Empty }); - } + methodInfo?.Invoke(control, new object[] { EventArgs.Empty }); } } #endregion WinFormsAdapter diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/WindowsFormsHostPropertyMap.cs b/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/WindowsFormsHostPropertyMap.cs index b7ecdd683a7..3d0611715cd 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/WindowsFormsHostPropertyMap.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/WindowsFormsHostPropertyMap.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -112,11 +112,11 @@ private void FlowDirectionPropertyTranslator(object host, string propertyName, o { case SW.FlowDirection.RightToLeft: adapter.RightToLeft = SWF.RightToLeft.Yes; - if (propertyInfo != null) { propertyInfo.SetValue(childControl, true, null); } + propertyInfo?.SetValue(childControl, true, null); break; case SW.FlowDirection.LeftToRight: adapter.RightToLeft = SWF.RightToLeft.No; - if (propertyInfo != null) { propertyInfo.SetValue(childControl, false, null); } + propertyInfo?.SetValue(childControl, false, null); break; } } From d072c42d8b735c0eb40c8b547bc7414edb8d6b9f Mon Sep 17 00:00:00 2001 From: Harshit Mishra Date: Wed, 18 Dec 2024 17:27:05 +0530 Subject: [PATCH 3/3] Address PR Review comments --- ...ows.Controls.Ribbon-ref-Net48.baseline.txt | 1 - .../UIAutomationProvider-ref.baseline.txt | 4 +-- .../System/Windows/Markup/XamlTypeMapper.cs | 28 +++++++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt index 66f72086f77..fcc74cf8643 100644 --- a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt +++ b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt @@ -1,2 +1 @@ -Compat issues with assembly System.Windows.Controls.Ribbon: Total Issues: 0 diff --git a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt index 641d6650c27..0e3a75ca1dd 100644 --- a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt +++ b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt @@ -11,7 +11,6 @@ CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeA CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderFragment' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderFragmentRoot' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderHwndOverride' in the contract but not the implementation. -CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderSimple' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IScrollItemProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IScrollProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ISelectionItemProvider' in the contract but not the implementation. @@ -20,10 +19,9 @@ CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeA CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITableItemProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITableProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITextProvider' in the contract but not the implementation. -CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITextRangeProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IToggleProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITransformProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IValueProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IVirtualizedItemProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IWindowProvider' in the contract but not the implementation. -Total Issues: 27 +Total Issues: 25 diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs index 71744c2705b..8dc4249e4ae 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs @@ -1405,7 +1405,19 @@ private MemberInfo GetClrInfoForClass( if (null != memberInfo) { - infoRecord?.SetPropertyMember(memberInfo); +#pragma warning disable IDE0031 + if (infoRecord != null) + { +#if !PBTCOMPILER + // DP's aren't present in the PBT case + if (infoRecord.DP == null) + { + infoRecord.DP = MapTable.GetDependencyProperty(infoRecord); + } +#endif + infoRecord.SetPropertyMember(memberInfo); + } +#pragma warning restore IDE0031 } } } @@ -1537,10 +1549,22 @@ private MemberInfo GetClrInfoForClass( memberInfo = PropertyInfoFromName(localName, baseType, tryInternal, true, out isInternal); } +#pragma warning disable IDE0031 if (null != memberInfo) { - infoRecord?.SetPropertyMember(memberInfo); + if (infoRecord != null) + { +#if !PBTCOMPILER + // DP's aren't present in the PBT case + if (infoRecord.DP == null) + { + infoRecord.DP = MapTable.GetDependencyProperty(infoRecord); + } +#endif + infoRecord.SetPropertyMember(memberInfo); + } } +#pragma warning restore IDE0031 } } }