Skip to content

Commit 4fc784e

Browse files
iSazonovdaxian-dbw
authored andcommitted
Bulk update code base to put 'null' on the right-hand-side of a comparison expression (PowerShell#6949)
1 parent c77d0ce commit 4fc784e

186 files changed

Lines changed: 1001 additions & 1009 deletions

File tree

Some content is hidden

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ internal class CimSessionProxy : IDisposable
226226
/// <param name="session">CimSession to be added</param>
227227
internal static void AddCimSessionToTemporaryCache(CimSession session)
228228
{
229-
if (null != session)
229+
if (session != null)
230230
{
231231
lock (temporarySessionCacheLock)
232232
{
@@ -252,7 +252,7 @@ internal static void AddCimSessionToTemporaryCache(CimSession session)
252252
private static void RemoveCimSessionFromTemporaryCache(CimSession session,
253253
bool dispose)
254254
{
255-
if (null != session)
255+
if (session != null)
256256
{
257257
bool removed = false;
258258
lock (temporarySessionCacheLock)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,15 @@ protected override void ProcessRecord()
317317
if (this.ClientOnly)
318318
{
319319
string conflictParameterName = null;
320-
if (null != this.ComputerName)
320+
if (this.ComputerName != null)
321321
{
322322
conflictParameterName = @"ComputerName";
323323
}
324-
else if (null != this.CimSession)
324+
else if (this.CimSession != null)
325325
{
326326
conflictParameterName = @"CimSession";
327327
}
328-
if (null != conflictParameterName)
328+
if (conflictParameterName != null)
329329
{
330330
ThrowConflictParameterWasSet(@"New-CimInstance", conflictParameterName, @"ClientOnly");
331331
return;

src/Microsoft.PowerShell.Commands.Management/commands/management/Eventlog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ private void Process(EventLog log)
403403
+ ": " + e.Message);
404404
throw;
405405
}
406-
if ((null != entry) &&
406+
if ((entry != null) &&
407407
((lastindex == Int32.MinValue
408408
|| lastindex - entry.Index == 1)))
409409
{

src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private static int ProcessComparison(Process x, Process y)
165165
/// <returns></returns>
166166
private void RetrieveMatchingProcessesByProcessName()
167167
{
168-
if (null == processNames)
168+
if (processNames == null)
169169
{
170170
_matchingProcesses = new List<Process>(AllProcesses);
171171
return;
@@ -206,7 +206,7 @@ private void RetrieveMatchingProcessesByProcessName()
206206
/// <returns></returns>
207207
private void RetrieveMatchingProcessesById()
208208
{
209-
if (null == processIds)
209+
if (processIds == null)
210210
{
211211
Diagnostics.Assert(false, "null processIds");
212212
throw PSTraceSource.NewInvalidOperationException();
@@ -241,7 +241,7 @@ private void RetrieveMatchingProcessesById()
241241
/// <returns></returns>
242242
private void RetrieveProcessesByInput()
243243
{
244-
if (null == InputObject)
244+
if (InputObject == null)
245245
{
246246
Diagnostics.Assert(false, "null InputObject");
247247
throw PSTraceSource.NewInvalidOperationException();
@@ -266,7 +266,7 @@ internal Process[] AllProcesses
266266
{
267267
get
268268
{
269-
if (null == _allProcesses)
269+
if (_allProcesses == null)
270270
{
271271
List<Process> processes = new List<Process>();
272272
processes.AddRange(Process.GetProcesses());
@@ -342,7 +342,7 @@ internal void WriteNonTerminatingError(
342342
string message = StringUtil.Format(resourceId,
343343
processName,
344344
processId,
345-
(null == innerException) ? string.Empty : innerException.Message);
345+
(innerException == null) ? string.Empty : innerException.Message);
346346
ProcessCommandException exception =
347347
new ProcessCommandException(message, innerException);
348348
exception.ProcessName = processName;
@@ -1399,7 +1399,7 @@ private void StopProcess(Process process)
13991399
exception = e;
14001400
}
14011401

1402-
if (null != exception)
1402+
if (exception != null)
14031403
{
14041404
if (!TryHasExited(process))
14051405
{

src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ internal void WriteNonTerminatingError(
103103
string message = StringUtil.Format(errorMessage,
104104
serviceName,
105105
displayName,
106-
(null == innerException) ? String.Empty : innerException.Message);
106+
(innerException == null) ? String.Empty : innerException.Message);
107107

108108
var exception = new ServiceCommandException(message, innerException);
109109
exception.ServiceName = serviceName;
@@ -261,7 +261,7 @@ internal ServiceController[] AllServices
261261
{
262262
get
263263
{
264-
if (null == _allServices)
264+
if (_allServices == null)
265265
{
266266
_allServices = ServiceController.GetServices();
267267
}
@@ -339,7 +339,7 @@ private List<ServiceController> MatchingServicesByServiceName()
339339
{
340340
List<ServiceController> matchingServices = new List<ServiceController>();
341341

342-
if (null == serviceNames)
342+
if (serviceNames == null)
343343
{
344344
foreach (ServiceController service in AllServices)
345345
{
@@ -399,7 +399,7 @@ private List<ServiceController> MatchingServicesByServiceName()
399399
private List<ServiceController> MatchingServicesByDisplayName()
400400
{
401401
List<ServiceController> matchingServices = new List<ServiceController>();
402-
if (null == DisplayName)
402+
if (DisplayName == null)
403403
{
404404
Diagnostics.Assert(false, "null DisplayName");
405405
throw PSTraceSource.NewInvalidOperationException();
@@ -439,7 +439,7 @@ private List<ServiceController> MatchingServicesByDisplayName()
439439
private List<ServiceController> MatchingServicesByInput()
440440
{
441441
List<ServiceController> matchingServices = new List<ServiceController>();
442-
if (null == InputObject)
442+
if (InputObject == null)
443443
{
444444
Diagnostics.Assert(false, "null InputObject");
445445
throw PSTraceSource.NewInvalidOperationException();
@@ -466,9 +466,9 @@ private void IncludeExcludeAdd(
466466
ServiceController service,
467467
bool checkDuplicates)
468468
{
469-
if (null != include && !Matches(service, include))
469+
if (include != null && !Matches(service, include))
470470
return;
471-
if (null != exclude && Matches(service, exclude))
471+
if (exclude != null && Matches(service, exclude))
472472
return;
473473
if (checkDuplicates)
474474
{
@@ -493,7 +493,7 @@ private void IncludeExcludeAdd(
493493
/// <returns></returns>
494494
private bool Matches(ServiceController service, string[] matchList)
495495
{
496-
if (null == matchList)
496+
if (matchList == null)
497497
throw PSTraceSource.NewArgumentNullException("matchList");
498498
string serviceID = (selectionMode == SelectionMode.DisplayName)
499499
? service.DisplayName
@@ -846,13 +846,13 @@ internal bool DoStartService(ServiceController serviceController)
846846
catch (InvalidOperationException e)
847847
{
848848
Win32Exception eInner = e.InnerException as Win32Exception;
849-
if (null == eInner
849+
if (eInner == null
850850
|| NativeMethods.ERROR_SERVICE_ALREADY_RUNNING != eInner.NativeErrorCode)
851851
{
852852
exception = e;
853853
}
854854
}
855-
if (null != exception)
855+
if (exception != null)
856856
{
857857
// This service refused to accept the start command,
858858
// so write a non-terminating error.
@@ -962,13 +962,13 @@ internal List<ServiceController> DoStopService(ServiceController serviceControll
962962
{
963963
Win32Exception eInner =
964964
e.InnerException as Win32Exception;
965-
if (null == eInner
965+
if (eInner == null
966966
|| NativeMethods.ERROR_SERVICE_NOT_ACTIVE != eInner.NativeErrorCode)
967967
{
968968
exception = e;
969969
}
970970
}
971-
if (null != exception)
971+
if (exception != null)
972972
{
973973
// This service refused to accept the stop command,
974974
// so write a non-terminating error.
@@ -1067,14 +1067,14 @@ internal bool DoPauseService(ServiceController serviceController)
10671067
catch (InvalidOperationException e)
10681068
{
10691069
Win32Exception eInner = e.InnerException as Win32Exception;
1070-
if (null != eInner
1070+
if (eInner != null
10711071
&& NativeMethods.ERROR_SERVICE_NOT_ACTIVE == eInner.NativeErrorCode)
10721072
{
10731073
serviceNotRunning = true;
10741074
}
10751075
exception = e;
10761076
}
1077-
if (null != exception)
1077+
if (exception != null)
10781078
{
10791079
// This service refused to accept the pause command,
10801080
// so write a non-terminating error.
@@ -1145,14 +1145,14 @@ internal bool DoResumeService(ServiceController serviceController)
11451145
catch (InvalidOperationException e)
11461146
{
11471147
Win32Exception eInner = e.InnerException as Win32Exception;
1148-
if (null != eInner
1148+
if (eInner != null
11491149
&& NativeMethods.ERROR_SERVICE_NOT_ACTIVE == eInner.NativeErrorCode)
11501150
{
11511151
serviceNotRunning = true;
11521152
}
11531153
exception = e;
11541154
}
1155-
if (null != exception)
1155+
if (exception != null)
11561156
{
11571157
// This service refused to accept the continue command,
11581158
// so write a non-terminating error.
@@ -1666,7 +1666,7 @@ protected override void ProcessRecord()
16661666
}
16671667
// Modify startup type or display name or credential
16681668
if (!String.IsNullOrEmpty(DisplayName)
1669-
|| ServiceStartupType.InvalidValue != StartupType || null != Credential)
1669+
|| ServiceStartupType.InvalidValue != StartupType || Credential != null)
16701670
{
16711671
DWORD dwStartType = NativeMethods.SERVICE_NO_CHANGE;
16721672
if (!NativeMethods.TryGetNativeStartupType(StartupType, out dwStartType))
@@ -1679,7 +1679,7 @@ protected override void ProcessRecord()
16791679
}
16801680

16811681
string username = null;
1682-
if (null != Credential)
1682+
if (Credential != null)
16831683
{
16841684
username = Credential.UserName;
16851685
password = Marshal.SecureStringToCoTaskMemUnicode(Credential.Password);
@@ -2024,7 +2024,7 @@ protected override void BeginProcessing()
20242024
}
20252025
// set up the double-null-terminated lpDependencies parameter
20262026
IntPtr lpDependencies = IntPtr.Zero;
2027-
if (null != DependsOn)
2027+
if (DependsOn != null)
20282028
{
20292029
int numchars = 1; // final null
20302030
foreach (string dependedOn in DependsOn)
@@ -2052,7 +2052,7 @@ protected override void BeginProcessing()
20522052

20532053
// set up the Credential parameter
20542054
string username = null;
2055-
if (null != Credential)
2055+
if (Credential != null)
20562056
{
20572057
username = Credential.UserName;
20582058
password = Marshal.SecureStringToCoTaskMemUnicode(Credential.Password);

src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected override void ProcessRecord()
7676
}
7777
else // ParameterSetName == "Name"
7878
{
79-
if (null != Name)
79+
if (Name != null)
8080
{
8181
// lookup each time zone name (or wildcard pattern)
8282
foreach (string tzname in Name)

src/Microsoft.PowerShell.Commands.Utility/commands/utility/CSVCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private void CreateFileStream()
408408
_fs.Dispose();
409409
_fs = null;
410410
// reset the read-only attribute
411-
if (null != _readOnlyFileInfo)
411+
if (_readOnlyFileInfo != null)
412412
_readOnlyFileInfo.Attributes |= FileAttributes.ReadOnly;
413413
}
414414
if (_helper != null)

src/Microsoft.PowerShell.Commands.Utility/commands/utility/ExportAliasCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ protected override void EndProcessing()
267267
writer = OpenFile(out readOnlyFileInfo);
268268
}
269269

270-
if (null != writer)
270+
if (writer != null)
271271
WriteHeader(writer);
272272

273273
// Now write out the aliases
@@ -284,7 +284,7 @@ protected override void EndProcessing()
284284
line = GetAliasLine(alias, "set-alias -Name:\"{0}\" -Value:\"{1}\" -Description:\"{2}\" -Option:\"{3}\"");
285285
}
286286

287-
if (null != writer)
287+
if (writer != null)
288288
writer.WriteLine(line);
289289

290290
if (PassThru)
@@ -295,10 +295,10 @@ protected override void EndProcessing()
295295
}
296296
finally
297297
{
298-
if (null != writer)
298+
if (writer != null)
299299
writer.Dispose();
300300
// reset the read-only attribute
301-
if (null != readOnlyFileInfo)
301+
if (readOnlyFileInfo != null)
302302
readOnlyFileInfo.Attributes |= FileAttributes.ReadOnly;
303303
}
304304
}

src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OriginalColumnInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal override Object GetValue(PSObject liveObject)
3333
// The live object has the liveObjectPropertyName property.
3434
Object liveObjectValue = propertyInfo.Value;
3535
ICollection collectionValue = liveObjectValue as ICollection;
36-
if (null != collectionValue)
36+
if (collectionValue != null)
3737
{
3838
liveObjectValue = _parentCmdlet.ConvertToString(PSObjectHelper.AsPSObject(propertyInfo.Value));
3939
}

src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutWindowProxy.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ internal OutWindowProxy(string title, OutputModeOption outPutMode, OutGridViewCo
5656
/// <param name="types">An array of types to add.</param>
5757
internal void AddColumns(string[] propertyNames, string[] displayNames, Type[] types)
5858
{
59-
if (null == propertyNames)
59+
if (propertyNames == null)
6060
{
6161
throw new ArgumentNullException("propertyNames");
6262
}
63-
if (null == displayNames)
63+
if (displayNames == null)
6464
{
6565
throw new ArgumentNullException("displayNames");
6666
}
67-
if (null == types)
67+
if (types == null)
6868
{
6969
throw new ArgumentNullException("types");
7070
}
@@ -173,7 +173,7 @@ private void AddExtraProperties(PSObject staleObject, PSObject liveObject)
173173
/// </param>
174174
internal void AddItem(PSObject livePSObject)
175175
{
176-
if (null == livePSObject)
176+
if (livePSObject == null)
177177
{
178178
throw new ArgumentNullException("livePSObject");
179179
}
@@ -199,7 +199,7 @@ internal void AddItem(PSObject livePSObject)
199199
/// </param>
200200
internal void AddHeteroViewItem(PSObject livePSObject)
201201
{
202-
if (null == livePSObject)
202+
if (livePSObject == null)
203203
{
204204
throw new ArgumentNullException("livePSObject");
205205
}

0 commit comments

Comments
 (0)