Skip to content

Commit 2966524

Browse files
authored
Use conditional access (#5592)
* Use conditional access Fixes #5591
1 parent 8ab6a48 commit 2966524

File tree

165 files changed

+386
-688
lines changed

Some content is hidden

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

165 files changed

+386
-688
lines changed

src/Build.OM.UnitTests/Construction/ProjectRootElement_Tests.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -935,10 +935,7 @@ public void SolutionCanNotBeOpened()
935935
}
936936
finally
937937
{
938-
if (security != null)
939-
{
940-
security.RemoveAccessRule(rule);
941-
}
938+
security?.RemoveAccessRule(rule);
942939

943940
File.Delete(solutionFile);
944941
File.Delete(tempFileSentinel);
@@ -983,10 +980,7 @@ public void ProjectCanNotBeOpened()
983980
}
984981
finally
985982
{
986-
if (security != null)
987-
{
988-
security.RemoveAccessRule(rule);
989-
}
983+
security?.RemoveAccessRule(rule);
990984

991985
File.Delete(projectFile);
992986
Assert.False(File.Exists(projectFile));

src/Build.UnitTests/BackEnd/Scheduler_Tests.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ public Scheduler_Tests()
6969
// Since we're creating our own BuildManager, we need to make sure that the default
7070
// one has properly relinquished the inproc node
7171
NodeProviderInProc nodeProviderInProc = ((IBuildComponentHost)BuildManager.DefaultBuildManager).GetComponent(BuildComponentType.InProcNodeProvider) as NodeProviderInProc;
72-
if (nodeProviderInProc != null)
73-
{
74-
nodeProviderInProc.Dispose();
75-
}
72+
nodeProviderInProc?.Dispose();
7673

7774
_host = new MockHost();
7875
_scheduler = new Scheduler();
@@ -379,10 +376,7 @@ public void VerifyRequestOrderingDoesNotAffectNodeCreationCountWithInProcAndAnyR
379376
// Since we're creating our own BuildManager, we need to make sure that the default
380377
// one has properly relinquished the inproc node
381378
NodeProviderInProc nodeProviderInProc = ((IBuildComponentHost)BuildManager.DefaultBuildManager).GetComponent(BuildComponentType.InProcNodeProvider) as NodeProviderInProc;
382-
if (nodeProviderInProc != null)
383-
{
384-
nodeProviderInProc.Dispose();
385-
}
379+
nodeProviderInProc?.Dispose();
386380

387381
_host = new MockHost();
388382
_host.BuildParameters.MaxNodeCount = 3;
@@ -543,10 +537,7 @@ public void VerifyNoOverCreationOfNodesWithBuildLoop()
543537
// Since we're creating our own BuildManager, we need to make sure that the default
544538
// one has properly relinquished the inproc node
545539
NodeProviderInProc nodeProviderInProc = ((IBuildComponentHost)BuildManager.DefaultBuildManager).GetComponent(BuildComponentType.InProcNodeProvider) as NodeProviderInProc;
546-
if (nodeProviderInProc != null)
547-
{
548-
nodeProviderInProc.Dispose();
549-
}
540+
nodeProviderInProc?.Dispose();
550541

551542
_host = new MockHost();
552543
_host.BuildParameters.MaxNodeCount = 3;

src/Build.UnitTests/BackEnd/TargetEntry_Tests.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,7 @@ public void AfterTargetsShouldReportFailedBuild()
836836
// Since we're creating our own BuildManager, we need to make sure that the default
837837
// one has properly relinquished the inproc node
838838
NodeProviderInProc nodeProviderInProc = ((IBuildComponentHost)BuildManager.DefaultBuildManager).GetComponent(BuildComponentType.InProcNodeProvider) as NodeProviderInProc;
839-
if (nodeProviderInProc != null)
840-
{
841-
nodeProviderInProc.Dispose();
842-
}
839+
nodeProviderInProc?.Dispose();
843840

844841
string content = @"
845842
<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
@@ -897,10 +894,7 @@ public void AfterTargetsShouldReportFailedBuild()
897894
{
898895
NodeProviderInProc inProcNodeProvider = ((IBuildComponentHost)manager).GetComponent(BuildComponentType.InProcNodeProvider) as NodeProviderInProc;
899896

900-
if (inProcNodeProvider != null)
901-
{
902-
inProcNodeProvider.Dispose();
903-
}
897+
inProcNodeProvider?.Dispose();
904898
}
905899
}
906900
}

src/Build.UnitTests/Construction/SolutionProjectGenerator_Tests.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,10 +1951,7 @@ public void BadFrameworkMonkierExpectBuildToFail()
19511951
// Since we're creating our own BuildManager, we need to make sure that the default
19521952
// one has properly relinquished the inproc node
19531953
NodeProviderInProc nodeProviderInProc = ((IBuildComponentHost)BuildManager.DefaultBuildManager).GetComponent(BuildComponentType.InProcNodeProvider) as NodeProviderInProc;
1954-
if (nodeProviderInProc != null)
1955-
{
1956-
nodeProviderInProc.Dispose();
1957-
}
1954+
nodeProviderInProc?.Dispose();
19581955

19591956
File.WriteAllText(projectFilePath, solutionFileContents.Replace('\'', '"'));
19601957
MockLogger logger = new MockLogger(output);
@@ -2042,10 +2039,7 @@ public void BadFrameworkMonkierExpectBuildToFail2()
20422039
// Since we're creating our own BuildManager, we need to make sure that the default
20432040
// one has properly relinquished the inproc node
20442041
NodeProviderInProc nodeProviderInProc = ((IBuildComponentHost)BuildManager.DefaultBuildManager).GetComponent(BuildComponentType.InProcNodeProvider) as NodeProviderInProc;
2045-
if (nodeProviderInProc != null)
2046-
{
2047-
nodeProviderInProc.Dispose();
2048-
}
2042+
nodeProviderInProc?.Dispose();
20492043

20502044
File.WriteAllText(projectFilePath, solutionFileContents.Replace('\'', '"'));
20512045
MockLogger logger = new MockLogger(output);

src/Build.UnitTests/Evaluation/ExpressionShredder_Tests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ private static void VerifyAgainstCanonicalResults(string test, HashSet<string> a
481481
{
482482
foreach (string result in actual)
483483
{
484-
if (expected == null || !expected.Contains(result))
484+
if (expected?.Contains(result) != true)
485485
{
486486
messages.Add("Found <" + result + "> in <" + test + "> but it wasn't expected");
487487
}
@@ -492,7 +492,7 @@ private static void VerifyAgainstCanonicalResults(string test, HashSet<string> a
492492
{
493493
foreach (string expect in expected)
494494
{
495-
if (actual == null || !actual.Contains(expect))
495+
if (actual?.Contains(expect) != true)
496496
{
497497
messages.Add("Did not find <" + expect + "> in <" + test + ">");
498498
}
@@ -530,7 +530,7 @@ private static void VerifyAgainstCanonicalResults(string test, IDictionary actua
530530
{
531531
foreach (DictionaryEntry result in actual)
532532
{
533-
if (expected == null || !expected.Contains(result.Key))
533+
if (expected?.Contains(result.Key) != true)
534534
{
535535
messages.Add("Found <" + result.Key + "> in <" + test + "> but it wasn't expected");
536536
}
@@ -541,7 +541,7 @@ private static void VerifyAgainstCanonicalResults(string test, IDictionary actua
541541
{
542542
foreach (DictionaryEntry expect in expected)
543543
{
544-
if (actual == null || !actual.Contains(expect.Key))
544+
if (actual?.Contains(expect.Key) != true)
545545
{
546546
messages.Add("Did not find <" + expect.Key + "> in <" + test + ">");
547547
}

src/Build.UnitTests/SolutionFileBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public string BuildSolution()
112112
Guid.NewGuid()
113113
.ToString("B")));
114114

115-
if (SolutionDependencies != null && SolutionDependencies.Length > 0)
115+
if (SolutionDependencies?.Length > 0)
116116
{
117117
foreach (var (parent, dependency) in SolutionDependencies)
118118
{
@@ -123,7 +123,7 @@ public string BuildSolution()
123123
}
124124
}
125125

126-
if (SolutionDependenciesProjectNameToGuids!= null && SolutionDependenciesProjectNameToGuids.Length > 0)
126+
if (SolutionDependenciesProjectNameToGuids?.Length > 0)
127127
{
128128
foreach (var (parent, dependencyGuids) in SolutionDependenciesProjectNameToGuids)
129129
{

src/Build/BackEnd/BuildManager/BuildManager.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,7 @@ public void EndBuild()
816816
Reset();
817817
_buildManagerState = BuildManagerState.Idle;
818818

819-
if (_threadException != null)
820-
{
821-
_threadException.Throw();
822-
}
819+
_threadException?.Throw();
823820

824821
if (BuildParameters.DumpOpportunisticInternStats)
825822
{
@@ -2367,7 +2364,7 @@ private static I ExpectPacketType<I>(INodePacket packet, NodePacketType expected
23672364
/// </summary>
23682365
private void SetOverallResultIfWarningsAsErrors(BuildResult result)
23692366
{
2370-
if (result != null && result.OverallResult == BuildResultCode.Success)
2367+
if (result?.OverallResult == BuildResultCode.Success)
23712368
{
23722369
ILoggingService loggingService = ((IBuildComponentHost)this).LoggingService;
23732370

src/Build/BackEnd/Components/BuildRequestEngine/BuildRequestEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public bool ResolveConfigurationRequest(int unresolvedConfigId, int configId)
230230
{
231231
lock (GlobalLock)
232232
{
233-
if (_unresolvedConfigurations == null || !_unresolvedConfigurations.ContainsKey(unresolvedConfigId))
233+
if (_unresolvedConfigurations?.ContainsKey(unresolvedConfigId) != true)
234234
{
235235
return false;
236236
}

src/Build/BackEnd/Components/Caching/ResultsCache.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,7 @@ public void ClearResultsForConfiguration(int configurationId)
230230
BuildResult removedResult;
231231
_resultsByConfiguration.TryRemove(configurationId, out removedResult);
232232

233-
if (removedResult != null)
234-
{
235-
removedResult.ClearCachedFiles();
236-
}
233+
removedResult?.ClearCachedFiles();
237234
}
238235
}
239236

src/Build/BackEnd/Components/Communications/NodeManager.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,9 @@ public void ShutdownConnectedNodes(bool enableReuse)
157157

158158
_nodesShutdown = true;
159159

160-
if (null != _inProcNodeProvider)
161-
{
162-
_inProcNodeProvider.ShutdownConnectedNodes(enableReuse);
163-
}
160+
_inProcNodeProvider?.ShutdownConnectedNodes(enableReuse);
164161

165-
if (null != _outOfProcNodeProvider)
166-
{
167-
_outOfProcNodeProvider.ShutdownConnectedNodes(enableReuse);
168-
}
162+
_outOfProcNodeProvider?.ShutdownConnectedNodes(enableReuse);
169163
}
170164

171165
/// <summary>
@@ -174,10 +168,7 @@ public void ShutdownConnectedNodes(bool enableReuse)
174168
public void ShutdownAllNodes()
175169
{
176170
// don't worry about inProc
177-
if (null != _outOfProcNodeProvider)
178-
{
179-
_outOfProcNodeProvider.ShutdownAllNodes();
180-
}
171+
_outOfProcNodeProvider?.ShutdownAllNodes();
181172
}
182173

183174
#endregion

0 commit comments

Comments
 (0)