Skip to content

Commit 5f4e100

Browse files
authored
Use null propagation operator for windows build (PowerShell#17795)
* Use null propagation in CimCmdlets * Use null propagation in Diagnostics and Management * ignore IDE0031 rule in ConsoleHost * Use null propagation in WSMan.Management * Use null propagation in SMA * ignore IDE0031 for securityDescHandle * cleanup after review
1 parent 4b4f1d1 commit 5f4e100

File tree

24 files changed

+60
-168
lines changed

24 files changed

+60
-168
lines changed

src/Microsoft.Management.Infrastructure.CimCmdlets/CimAsyncOperation.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,7 @@ private void Cleanup()
528528
}
529529

530530
this.moreActionEvent.Dispose();
531-
if (this.ackedEvent != null)
532-
{
533-
this.ackedEvent.Dispose();
534-
}
531+
this.ackedEvent?.Dispose();
535532

536533
DebugHelper.WriteLog("Cleanup complete.", 2);
537534
}

src/Microsoft.Management.Infrastructure.CimCmdlets/CimBaseAction.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,7 @@ protected virtual void Dispose(bool disposing)
168168
if (disposing)
169169
{
170170
// Dispose managed resources.
171-
if (this.completeEvent != null)
172-
{
173-
this.completeEvent.Dispose();
174-
}
171+
this.completeEvent?.Dispose();
175172
}
176173

177174
// Call the appropriate methods to clean up

src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,7 @@ internal void SetParameter(object value, string parameterName)
470470
return;
471471
}
472472

473-
if (this.parameterBinder != null)
474-
{
475-
this.parameterBinder.SetParameter(parameterName, this.AtBeginProcess);
476-
}
473+
this.parameterBinder?.SetParameter(parameterName, this.AtBeginProcess);
477474
}
478475
#endregion
479476

@@ -576,10 +573,7 @@ protected void Dispose(bool disposing)
576573
protected virtual void DisposeInternal()
577574
{
578575
// Dispose managed resources.
579-
if (this.operation != null)
580-
{
581-
this.operation.Dispose();
582-
}
576+
this.operation?.Dispose();
583577
}
584578
#endregion
585579

src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimAssociatedInstanceCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ protected override void ProcessRecord()
232232
protected override void EndProcessing()
233233
{
234234
CimGetAssociatedInstance operation = this.GetOperationAgent();
235-
if (operation != null)
236-
operation.ProcessRemainActions(this.CmdletOperation);
235+
operation?.ProcessRemainActions(this.CmdletOperation);
237236
}
238237

239238
#endregion

src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimClassCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,7 @@ protected override void ProcessRecord()
202202
protected override void EndProcessing()
203203
{
204204
CimGetCimClass cimGetCimClass = this.GetOperationAgent();
205-
if (cimGetCimClass != null)
206-
{
207-
cimGetCimClass.ProcessRemainActions(this.CmdletOperation);
208-
}
205+
cimGetCimClass?.ProcessRemainActions(this.CmdletOperation);
209206
}
210207

211208
#endregion

src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimInstanceCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,7 @@ protected override void ProcessRecord()
491491
protected override void EndProcessing()
492492
{
493493
CimGetInstance cimGetInstance = this.GetOperationAgent();
494-
if (cimGetInstance != null)
495-
{
496-
cimGetInstance.ProcessRemainActions(this.CmdletOperation);
497-
}
494+
cimGetInstance?.ProcessRemainActions(this.CmdletOperation);
498495
}
499496

500497
#endregion

src/Microsoft.Management.Infrastructure.CimCmdlets/InvokeCimMethodCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,7 @@ protected override void ProcessRecord()
408408
protected override void EndProcessing()
409409
{
410410
CimInvokeCimMethod cimInvokeMethod = this.GetOperationAgent();
411-
if (cimInvokeMethod != null)
412-
{
413-
cimInvokeMethod.ProcessRemainActions(this.CmdletOperation);
414-
}
411+
cimInvokeMethod?.ProcessRemainActions(this.CmdletOperation);
415412
}
416413

417414
#endregion

src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimInstanceCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,7 @@ protected override void ProcessRecord()
377377
protected override void EndProcessing()
378378
{
379379
CimNewCimInstance cimNewCimInstance = this.GetOperationAgent();
380-
if (cimNewCimInstance != null)
381-
{
382-
cimNewCimInstance.ProcessRemainActions(this.CmdletOperation);
383-
}
380+
cimNewCimInstance?.ProcessRemainActions(this.CmdletOperation);
384381
}
385382

386383
#endregion

src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,7 @@ protected override void DisposeInternal()
334334
base.DisposeInternal();
335335

336336
// Dispose managed resources.
337-
if (this.cimNewSession != null)
338-
{
339-
this.cimNewSession.Dispose();
340-
}
337+
this.cimNewSession?.Dispose();
341338
}
342339
#endregion
343340
}

src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,7 @@ protected override object GetSourceObject()
227227
break;
228228
}
229229

230-
if (watcher != null)
231-
{
232-
watcher.SetCmdlet(this);
233-
}
230+
watcher?.SetCmdlet(this);
234231

235232
return watcher;
236233
}
@@ -275,10 +272,7 @@ private static void newSubscriber_Unsubscribed(
275272
DebugHelper.WriteLogEx();
276273

277274
CimIndicationWatcher watcher = sender as CimIndicationWatcher;
278-
if (watcher != null)
279-
{
280-
watcher.Stop();
281-
}
275+
watcher?.Stop();
282276
}
283277

284278
#region private members

0 commit comments

Comments
 (0)