Skip to content

Commit 1154c80

Browse files
authored
Resolve suppressed IDE0031 warnings (#10812)
Those were temporarily suppressed in 90cfb1a I used Visual Studio to fix all of them automatically.
1 parent 90cfb1a commit 1154c80

File tree

103 files changed

+276
-899
lines changed

Some content is hidden

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

103 files changed

+276
-899
lines changed

Directory.Build.props

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<TargetFramework>net10.0</TargetFramework>
77
<TargetFrameworkVersion>10.0</TargetFrameworkVersion>
88
<BuildWithNetFrameworkHostedCompiler>true</BuildWithNetFrameworkHostedCompiler>
9-
<!-- Temporarily disable IDE0031: Null check can be simplified warnings. -->
10-
<NoWarn>$(NoWarn);IDE0031</NoWarn>
119
</PropertyGroup>
1210
<!-- Normalize $(TestWpfArcadeSdkPath) by appending a '\' to it if one is missing -->
1311
<PropertyGroup Condition="'$(TestWpfArcadeSdkPath)'!=''">

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/AnnotationHighlightLayer.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1114,8 +1114,7 @@ protected override Geometry DefiningGeometry
11141114

11151115
//reset render transformation of the TopOwner
11161116
UIElement uie = TopOwner as UIElement;
1117-
if (uie != null)
1118-
uie.RenderTransform = Transform.Identity;
1117+
uie?.RenderTransform = Transform.Identity;
11191118

11201119
return geometry;
11211120
}

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/MarkedHighlightComponent.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,10 @@ private void SetMarkerTransform(Path marker, ITextPointer anchor, ITextPointer b
407407
topTailTransform.Children.Add(tailScale);
408408
topTailTransform.Children.Add(topOffset);
409409

410-
if (geometry.Children[0] != null)
411-
geometry.Children[0].Transform = topTailTransform;
410+
geometry.Children[0]?.Transform = topTailTransform;
412411

413-
if (geometry.Children[1] != null)
414-
geometry.Children[1].Transform = bodyTransform;
415-
if (geometry.Children[2] != null)
416-
geometry.Children[2].Transform = bottomTailTransform;
412+
geometry.Children[1]?.Transform = bodyTransform;
413+
geometry.Children[2]?.Transform = bottomTailTransform;
417414

418415
//add transform to base anchor if needed
419416
if (baseAnchor != null)

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/ActiveXContainer.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
//
@@ -46,8 +46,7 @@ internal ActiveXContainer(ActiveXHost host)
4646
//
4747
int UnsafeNativeMethods.IOleContainer.ParseDisplayName(Object pbc, string pszDisplayName, int[] pchEaten, Object[] ppmkOut)
4848
{
49-
if (ppmkOut != null)
50-
ppmkOut[0] = null;
49+
ppmkOut?[0] = null;
5150

5251
return NativeMethods.E_NOTIMPL;
5352
}

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,7 @@ bool IAnnotationComponent.IsDirty
11371137
}
11381138
set
11391139
{
1140-
if (_anchor != null)
1141-
_anchor.IsDirty = value;
1140+
_anchor?.IsDirty = value;
11421141
if (value)
11431142
InvalidateVisual();
11441143
}

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/LiveShapingBlock.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
//
@@ -26,8 +26,7 @@ internal LiveShapingList List
2626
public override LiveShapingItem SetItemAt(int offset, LiveShapingItem lsi)
2727
{
2828
base.SetItemAt(offset, lsi);
29-
if (lsi != null)
30-
lsi.Block = this;
29+
lsi?.Block = this;
3130
return lsi;
3231
}
3332

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/RBNode.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ private RBNode<T> Substitute(RBNode<T> node, RBNode<T> sub, RBNode<T> parent)
548548
sub.Parent = node.Parent;
549549
sub.IsRed = node.IsRed;
550550

551-
if (sub.LeftChild != null) sub.LeftChild.Parent = sub;
552-
if (sub.RightChild != null) sub.RightChild.Parent = sub;
551+
sub.LeftChild?.Parent = sub;
552+
sub.RightChild?.Parent = sub;
553553
return sub;
554554
}
555555

@@ -624,7 +624,7 @@ private RBNode<T> RotateLeft()
624624
node.IsRed = this.IsRed;
625625
node.Parent = this.Parent;
626626
this.RightChild = node.LeftChild;
627-
if (this.RightChild != null) this.RightChild.Parent = this;
627+
this.RightChild?.Parent = this;
628628
node.LeftChild = this;
629629
this.IsRed = true;
630630
this.Parent = node;
@@ -638,7 +638,7 @@ private RBNode<T> RotateRight()
638638
node.IsRed = this.IsRed;
639639
node.Parent = this.Parent;
640640
this.LeftChild = node.RightChild;
641-
if (this.LeftChild != null) this.LeftChild.Parent = this;
641+
this.LeftChild?.Parent = this;
642642
node.RightChild = this;
643643
this.IsRed = true;
644644
this.Parent = node;
@@ -836,8 +836,8 @@ protected RBNode<T> LoadTree(ref string s)
836836

837837
node.LeftChild = LoadTree(ref s); // read subtrees
838838
node.RightChild = LoadTree(ref s);
839-
if (node.LeftChild != null) node.LeftChild.Parent = node;
840-
if (node.RightChild != null) node.RightChild.Parent = node;
839+
node.LeftChild?.Parent = node;
840+
node.RightChild?.Parent = node;
841841

842842
s = s.Substring(1); // skip ')'
843843

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/RBTree.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,7 @@ internal RBNode<T> InsertNode(int index)
424424
internal void RemoveNode(int index)
425425
{
426426
LeftChild = DeleteNode(this, LeftChild, index);
427-
if (LeftChild != null)
428-
LeftChild.IsRed = false;
427+
LeftChild?.IsRed = false;
429428
}
430429

431430
internal virtual RBNode<T> NewNode()
@@ -500,8 +499,7 @@ public void RemoveAt(int index)
500499

501500
RBFinger<T> finger = FindIndex(index, true);
502501
RemoveAt(ref finger);
503-
if (LeftChild != null)
504-
LeftChild.IsRed = false;
502+
LeftChild?.IsRed = false;
505503

506504
Verify(size - 1);
507505
}
@@ -593,8 +591,7 @@ public bool Remove(T item)
593591
RBFinger<T> finger = Find(item, Comparison);
594592
if (finger.Found)
595593
RemoveAt(ref finger);
596-
if (LeftChild != null)
597-
LeftChild.IsRed = false;
594+
LeftChild?.IsRed = false;
598595
return finger.Found;
599596
}
600597

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Printing/PrintDlgExMarshaler.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,7 @@ string printerName
334334
}
335335
}
336336
}
337-
if (printQueue != null)
338-
{
339-
printQueue.InPartialTrust = true;
340-
}
337+
printQueue?.InPartialTrust = true;
341338

342339
return printQueue;
343340
}

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParagraph.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1189,14 +1189,8 @@ private void BuildUpdateRecord()
11891189
}
11901190
while (paraInvalid != ur.SyncPara)
11911191
{
1192-
if (paraInvalid.Next != null)
1193-
{
1194-
paraInvalid.Next.Previous = null;
1195-
}
1196-
if (paraInvalid.Previous != null)
1197-
{
1198-
paraInvalid.Previous.Next = null;
1199-
}
1192+
paraInvalid.Next?.Previous = null;
1193+
paraInvalid.Previous?.Next = null;
12001194
paraInvalid.Dispose();
12011195
paraInvalid = paraInvalid.Next;
12021196
}

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TextFormatterHost.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44

@@ -39,10 +39,7 @@ public override TextRun GetTextRun(int textSourceCharacterIndex)
3939
Debug.Assert(Context != null, "TextFormatter host is not initialized.");
4040
Debug.Assert(textSourceCharacterIndex >= 0, "Character index must be non-negative.");
4141
TextRun run = Context.GetTextRun(textSourceCharacterIndex);
42-
if (run.Properties != null)
43-
{
44-
run.Properties.PixelsPerDip = PixelsPerDip;
45-
}
42+
run.Properties?.PixelsPerDip = PixelsPerDip;
4643

4744
return run;
4845
}

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/ComplexLine.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ public override TextRun GetTextRun(int dcp)
6262
}
6363
Debug.Assert(run != null, "TextRun has not been created.");
6464
Debug.Assert(run.Length > 0, "TextRun has to have positive length.");
65-
if (run.Properties != null)
66-
{
67-
run.Properties.PixelsPerDip = this.PixelsPerDip;
68-
}
65+
run.Properties?.PixelsPerDip = this.PixelsPerDip;
6966

7067
return run;
7168
}

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/SimpleLine.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44

@@ -57,10 +57,7 @@ public override TextRun GetTextRun(int dcp)
5757
run = new TextEndOfParagraph(_syntheticCharacterLength);
5858
}
5959

60-
if (run.Properties != null)
61-
{
62-
run.Properties.PixelsPerDip = this.PixelsPerDip;
63-
}
60+
run.Properties?.PixelsPerDip = this.PixelsPerDip;
6461

6562
return run;
6663
}

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,7 @@ public bool ShowPageBorders
853853
{
854854
DocumentGridPage dp = _childrenCollection[i] as DocumentGridPage;
855855

856-
if (dp != null)
857-
{
858-
dp.ShowPageBorders = _showPageBorders;
859-
}
856+
dp?.ShowPageBorders = _showPageBorders;
860857
}
861858
}
862859
}

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentView.cs

+4-16
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,7 @@ protected override int VisualChildrenCount
261261
internal void SuspendLayout()
262262
{
263263
_suspendLayout = true;
264-
if (_pageVisual != null)
265-
{
266-
_pageVisual.Opacity = 0.5;
267-
}
264+
_pageVisual?.Opacity = 0.5;
268265
}
269266

270267
/// <summary>
@@ -273,10 +270,7 @@ internal void SuspendLayout()
273270
internal void ResumeLayout()
274271
{
275272
_suspendLayout = false;
276-
if (_pageVisual != null)
277-
{
278-
_pageVisual.Opacity = 1.0;
279-
}
273+
_pageVisual?.Opacity = 1.0;
280274
InvalidateMeasure();
281275
}
282276

@@ -552,10 +546,7 @@ bool IScrollInfo.CanVerticallyScroll
552546
}
553547
set
554548
{
555-
if (_scrollData != null)
556-
{
557-
_scrollData.CanVerticallyScroll = value;
558-
}
549+
_scrollData?.CanVerticallyScroll = value;
559550
}
560551
}
561552

@@ -570,10 +561,7 @@ bool IScrollInfo.CanHorizontallyScroll
570561
}
571562
set
572563
{
573-
if (_scrollData != null)
574-
{
575-
_scrollData.CanHorizontallyScroll = value;
576-
}
564+
_scrollData?.CanHorizontallyScroll = value;
577565
}
578566
}
579567

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/ParentUndoUnit.cs

+4-16
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,11 @@ public virtual void Open(IParentUndoUnit newUnit)
7070
}
7171

7272
_openedUnit = newUnit;
73-
if (newUnit != null)
74-
{
75-
newUnit.Container = this;
76-
}
73+
newUnit?.Container = this;
7774
}
7875
else
7976
{
80-
if (newUnit != null)
81-
{
82-
newUnit.Container = deepestOpen;
83-
}
77+
newUnit?.Container = deepestOpen;
8478

8579
deepestOpen.Open(newUnit);
8680
}
@@ -153,10 +147,7 @@ public virtual void Close(IParentUndoUnit unit, UndoCloseAction closeAction)
153147
if (closeAction != UndoCloseAction.Commit)
154148
{
155149
// discard unit
156-
if (undoManager != null)
157-
{
158-
undoManager.IsEnabled = false;
159-
}
150+
undoManager?.IsEnabled = false;
160151

161152
if (OpenedUnit.OpenedUnit != null)
162153
{
@@ -180,10 +171,7 @@ public virtual void Close(IParentUndoUnit unit, UndoCloseAction closeAction)
180171
((IParentUndoUnit)TopContainer).OnNextDiscard();
181172
}
182173

183-
if (undoManager != null)
184-
{
185-
undoManager.IsEnabled = true;
186-
}
174+
undoManager?.IsEnabled = true;
187175
}
188176
else
189177
{

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxLine.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
//
@@ -89,10 +89,7 @@ public override TextRun GetTextRun(int dcp)
8989
}
9090
Invariant.Assert(run != null, "TextRun has not been created.");
9191
Invariant.Assert(run.Length > 0, "TextRun has to have positive length.");
92-
if (run.Properties != null)
93-
{
94-
run.Properties.PixelsPerDip = this.PixelsPerDip;
95-
}
92+
run.Properties?.PixelsPerDip = this.PixelsPerDip;
9693

9794
return run;
9895
}

0 commit comments

Comments
 (0)