Skip to content

Commit e8c17c1

Browse files
authored
Use 'string.IsNullOrEmpty' method (#5588)
Co-authored-by: Lachlan Ennis <lachlan@expert1.com.au>
1 parent 629447b commit e8c17c1

39 files changed

+98
-99
lines changed

src/Build/BackEnd/Components/RequestBuilder/TargetEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ private List<string> GetBatchableParametersForTarget()
917917
batchableTargetParameters.Add(_target.Outputs);
918918
}
919919

920-
if (_target.Returns != null && _target.Returns.Length > 0)
920+
if (!string.IsNullOrEmpty(_target.Returns))
921921
{
922922
batchableTargetParameters.Add(_target.Returns);
923923
}

src/Build/Errors/InternalLoggerException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ bool initializationException
9191
)
9292
: base(message, innerException)
9393
{
94-
ErrorUtilities.VerifyThrow((message != null) && (message.Length > 0), "Need error message.");
94+
ErrorUtilities.VerifyThrow(!string.IsNullOrEmpty(message), "Need error message.");
9595
ErrorUtilities.VerifyThrow(innerException != null || initializationException, "Need the logger exception.");
96-
ErrorUtilities.VerifyThrow((errorCode != null) && (errorCode.Length > 0), "Must specify the error message code.");
97-
ErrorUtilities.VerifyThrow((helpKeyword != null) && (helpKeyword.Length > 0), "Must specify the help keyword for the IDE.");
96+
ErrorUtilities.VerifyThrow(!string.IsNullOrEmpty(errorCode), "Must specify the error message code.");
97+
ErrorUtilities.VerifyThrow(!string.IsNullOrEmpty(helpKeyword), "Must specify the help keyword for the IDE.");
9898

9999
this.e = e;
100100
this.errorCode = errorCode;

src/Build/Evaluation/Expander.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,7 +2553,7 @@ internal static IEnumerable<Pair<string, S>> ExpandQuotedExpressionFunction(Expa
25532553
// the caller to possibly do correlation.
25542554

25552555
// We pass in the existing item so we can copy over its metadata
2556-
if (include != null && include.Length > 0)
2556+
if (!string.IsNullOrEmpty(include))
25572557
{
25582558
yield return new Pair<string, S>(include, item.Value);
25592559
}
@@ -2652,7 +2652,7 @@ internal static IEnumerable<Pair<string, S>> HasMetadata(Expander<P, I> expander
26522652

26532653
// GetMetadataValueEscaped returns empty string for missing metadata,
26542654
// but IItem specifies it should return null
2655-
if (metadataValue != null && metadataValue.Length > 0)
2655+
if (!string.IsNullOrEmpty(metadataValue))
26562656
{
26572657
// return a result through the enumerator
26582658
yield return new Pair<string, S>(item.Key, item.Value);

src/Build/Instance/ProjectItemInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ public string GetMetadata(string metadataName)
12361236
/// </summary>
12371237
public string GetMetadataEscaped(string metadataName)
12381238
{
1239-
if (metadataName == null || metadataName.Length == 0)
1239+
if (string.IsNullOrEmpty(metadataName))
12401240
{
12411241
ErrorUtilities.VerifyThrowArgumentLength(metadataName, "metadataName");
12421242
}

src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ private void DisplayDeferredProjectStartedEvent(BuildEventContext e)
14841484
WriteLinePrefix(projectStartedEvent.FullProjectKey, projectStartedEvent.TimeStamp, false);
14851485
setColor(ConsoleColor.Cyan);
14861486
string message;
1487-
if ((targetNames == null) || (targetNames.Length == 0))
1487+
if (string.IsNullOrEmpty(targetNames))
14881488
{
14891489
message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedTopLevelProjectWithDefaultTargets", current, currentProjectNodeId);
14901490
}
@@ -1500,7 +1500,7 @@ private void DisplayDeferredProjectStartedEvent(BuildEventContext e)
15001500
{
15011501
WriteLinePrefix(parentStartedEvent.FullProjectKey, parentStartedEvent.TimeStamp, false);
15021502
setColor(ConsoleColor.Cyan);
1503-
if ((targetNames == null) || (targetNames.Length == 0))
1503+
if (string.IsNullOrEmpty(targetNames))
15041504
{
15051505
WriteMessageAligned(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedWithDefaultTargetsMultiProc", previous, parentStartedEvent.FullProjectKey, current, projectStartedEvent.FullProjectKey, currentProjectNodeId), true);
15061506
}

src/Build/Logging/SerialConsoleLogger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ private void WriteProjectStartedText(string current, string targetNames, string
636636

637637
if (previous == null)
638638
{
639-
if ((targetNames == null) || (targetNames.Length == 0))
639+
if (string.IsNullOrEmpty(targetNames))
640640
{
641641
WriteLinePrettyFromResource(indentLevel, "ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", current);
642642
}
@@ -647,7 +647,7 @@ private void WriteProjectStartedText(string current, string targetNames, string
647647
}
648648
else
649649
{
650-
if ((targetNames == null) || (targetNames.Length == 0))
650+
if (string.IsNullOrEmpty(targetNames))
651651
{
652652
WriteLinePrettyFromResource(indentLevel, "ProjectStartedPrefixForNestedProjectWithDefaultTargets", previous, current);
653653
}

src/Deprecated/Conversion/ProjectFileConverter.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ private void DoConvert()
372372
{
373373
// Make sure we were passed in non-empty source and destination project
374374
// file names.
375-
error.VerifyThrowArgument((this.oldProjectFile != null) && (this.oldProjectFile.Length > 0),
375+
error.VerifyThrowArgument(!string.IsNullOrEmpty(this.oldProjectFile),
376376
"MissingOldProjectFile");
377-
error.VerifyThrowArgument((this.newProjectFile != null) && (this.newProjectFile.Length > 0),
377+
error.VerifyThrowArgument(!string.IsNullOrEmpty(this.newProjectFile),
378378
"MissingNewProjectFile");
379379

380380
ConvertInMemoryToMSBuildProject();
@@ -425,7 +425,7 @@ private void ConvertInMemoryToMSBuildProject()
425425
{
426426
// Make sure we were passed in non-empty source and destination project
427427
// file names.
428-
error.VerifyThrowArgument((this.oldProjectFile != null) && (this.oldProjectFile.Length > 0),
428+
error.VerifyThrowArgument(!string.IsNullOrEmpty(this.oldProjectFile),
429429
"MissingOldProjectFile");
430430

431431
// Make sure the source project file exists.
@@ -1438,7 +1438,7 @@ XmlElementWithLocation visualStudioProjectElement
14381438
// to convert a VC++ or some other type of project, and give a more friendly
14391439
// error message.
14401440
string projectType = visualStudioProjectElement.GetAttribute(VSProjectAttributes.projectType);
1441-
ProjectErrorUtilities.VerifyThrowInvalidProject((projectType == null) || (projectType.Length == 0),
1441+
ProjectErrorUtilities.VerifyThrowInvalidProject(string.IsNullOrEmpty(projectType),
14421442
visualStudioProjectElement.Location, "ProjectTypeCannotBeConverted", projectType);
14431443

14441444
// Make sure the <VisualStudioProject> tag doesn't have any attributes.
@@ -1518,8 +1518,8 @@ XmlElementWithLocation languageElement
15181518
// Get the project type for this project file. We only support "Local". We do not
15191519
// convert web projects -- that's Venus's job.
15201520
string projectType = languageElement.GetAttribute(VSProjectAttributes.projectType);
1521-
ProjectErrorUtilities.VerifyThrowInvalidProject(projectType == null || projectType.Length == 0 ||
1522-
(String.Equals(projectType, VSProjectAttributes.local, StringComparison.OrdinalIgnoreCase)),
1521+
ProjectErrorUtilities.VerifyThrowInvalidProject(string.IsNullOrEmpty(projectType) ||
1522+
(String.Compare(projectType, VSProjectAttributes.local, StringComparison.OrdinalIgnoreCase) == 0),
15231523
languageElement.Location, "ProjectTypeCannotBeConverted", projectType);
15241524

15251525
// All of the attributes on the language tag get converted to XMake
@@ -1557,7 +1557,7 @@ XmlElementWithLocation languageElement
15571557
// -----------------------------------------------------------------------
15581558

15591559
string originalMyType = languageElement.GetAttribute(XMakeProjectStrings.myType);
1560-
if ((originalMyType != null) && (originalMyType.Length != 0))
1560+
if (!string.IsNullOrEmpty(originalMyType))
15611561
{
15621562
// Flag the fact that the Everett project already had a MyType property in there,
15631563
// so we don't try to override it later.
@@ -1710,7 +1710,7 @@ private void AddFinalPropertiesAndImports(XmlElementWithLocation languageElement
17101710
!isTriumphProject // Doesn't apply to Triumph->Trinity conversions.
17111711
)
17121712
{
1713-
if (this.outputType != null && this.outputType.Length > 0)
1713+
if (!string.IsNullOrEmpty(this.outputType))
17141714
{
17151715
if (String.Equals(this.outputType, XMakeProjectStrings.winExe, StringComparison.OrdinalIgnoreCase))
17161716
{
@@ -2070,7 +2070,7 @@ XmlElementWithLocation configElement
20702070

20712071
// Get the "Name" attribute of the <Config> element.
20722072
string configName = configElement.GetAttribute(VSProjectAttributes.name);
2073-
ProjectErrorUtilities.VerifyThrowInvalidProject((configName != null) && (configName.Length > 0),
2073+
ProjectErrorUtilities.VerifyThrowInvalidProject(!string.IsNullOrEmpty(configName),
20742074
configElement.Location, "MissingAttribute", VSProjectElements.config, VSProjectAttributes.name);
20752075

20762076
// In the case of VSD projects, the "Name" attribute will have a pipe in it,
@@ -2108,7 +2108,7 @@ XmlElementWithLocation configElement
21082108

21092109
// Process OutputPath attribute separately to ensure it contains trailing backslash
21102110
string outputPath = configElement.GetAttribute(VSProjectAttributes.outputPath);
2111-
if (outputPath != null && outputPath.Length > 0)
2111+
if (!string.IsNullOrEmpty(outputPath))
21122112
{
21132113
if (outputPath[outputPath.Length-1] != Path.DirectorySeparatorChar)
21142114
outputPath += Path.DirectorySeparatorChar;
@@ -2133,7 +2133,7 @@ XmlElementWithLocation configElement
21332133

21342134
// Get rid of the "IncrementalBuild" attribute
21352135
string incrementalBuild = configElement.GetAttribute ( VSProjectAttributes.incrementalBuild );
2136-
if (incrementalBuild != null && incrementalBuild.Length > 0)
2136+
if (!string.IsNullOrEmpty(incrementalBuild))
21372137
{
21382138
configElement.RemoveAttribute ( VSProjectAttributes.incrementalBuild );
21392139
}
@@ -2278,7 +2278,7 @@ XmlElementWithLocation platformElement
22782278

22792279
// Get the "Name" attribute of the <Platform> element.
22802280
platformForVSD = platformElement.GetAttribute(VSProjectAttributes.name);
2281-
ProjectErrorUtilities.VerifyThrowInvalidProject((platformForVSD != null) && (platformForVSD.Length > 0),
2281+
ProjectErrorUtilities.VerifyThrowInvalidProject(!string.IsNullOrEmpty(platformForVSD),
22822282
platformElement.Location, "MissingAttribute", VSProjectElements.platform, VSProjectAttributes.name);
22832283

22842284
// Create a new property group, and add all of the XML attributes as XMake
@@ -2502,7 +2502,7 @@ ProjectItemGroupElement referencesItemGroup
25022502
// "-Designer", we need to disregard this reference entirely.
25032503

25042504
string platform = referenceElement.GetAttribute(VSProjectAttributes.platform);
2505-
if ((platform != null) && (platform.Length > 0))
2505+
if (!string.IsNullOrEmpty(platform))
25062506
{
25072507
if (platform.IndexOf("-Designer", 0, platform.Length, StringComparison.Ordinal) != -1)
25082508
{
@@ -2517,7 +2517,7 @@ ProjectItemGroupElement referencesItemGroup
25172517
// Get the "Name" attribute. This is a required attribute in the VS7/
25182518
// Everett format.
25192519
string referenceName = referenceElement.GetAttribute(VSProjectAttributes.name);
2520-
ProjectErrorUtilities.VerifyThrowInvalidProject((referenceName != null) && (referenceName.Length > 0),
2520+
ProjectErrorUtilities.VerifyThrowInvalidProject(!string.IsNullOrEmpty(referenceName),
25212521
referenceElement.Location, "MissingAttribute", VSProjectAttributes.name, VSProjectElements.reference);
25222522

25232523
// Before we go any further, we must special-case some assemblies for VSD projects.
@@ -2559,12 +2559,12 @@ ProjectItemGroupElement referencesItemGroup
25592559
// reference.
25602560
string referencedProjectGuid = referenceElement.GetAttribute(VSProjectAttributes.project);
25612561

2562-
if ((comReferenceGuid != null) && (comReferenceGuid.Length > 0) &&
2562+
if (!string.IsNullOrEmpty(comReferenceGuid) &&
25632563
(comReferenceGuid != "{00000000-0000-0000-0000-000000000000}"))
25642564
{
25652565
newReferenceItem = ConvertClassicComReference(referenceElement, referencesItemGroup, referenceName);
25662566
}
2567-
else if ((referencedProjectGuid != null) && (referencedProjectGuid.Length > 0))
2567+
else if (!string.IsNullOrEmpty(referencedProjectGuid))
25682568
{
25692569
newReferenceItem = ConvertProjectToProjectReference(referenceElement, referencesItemGroup, referenceName, ref referencedProjectGuid);
25702570
}
@@ -2738,7 +2738,7 @@ private ProjectItemElement ConvertAssemblyReference(XmlElementWithLocation refer
27382738
// Get the "AssemblyName" attribute. If not found, just use the value from the
27392739
// "Name" attribute. This is what the project loading code does in VS.
27402740
string assemblyName = referenceElement.GetAttribute(VSProjectAttributes.assemblyName);
2741-
if ((assemblyName == null) || (assemblyName.Length == 0))
2741+
if (string.IsNullOrEmpty(assemblyName))
27422742
{
27432743
assemblyName = referenceName;
27442744
}
@@ -3022,7 +3022,7 @@ ProjectItemGroupElement importsItemGroup
30223022

30233023
// Get the required "Namespace" attribute.
30243024
string importNamespace = importElement.GetAttribute(VSProjectAttributes.importNamespace);
3025-
ProjectErrorUtilities.VerifyThrowInvalidProject((importNamespace != null) && (importNamespace.Length > 0),
3025+
ProjectErrorUtilities.VerifyThrowInvalidProject(!string.IsNullOrEmpty(importNamespace),
30263026
importElement.Location, "MissingAttribute", VSProjectAttributes.importNamespace, VSProjectElements.import);
30273027
// Remove the "Namespace" attribute, so it doesn't show up in our loop later.
30283028
importElement.RemoveAttribute(VSProjectAttributes.importNamespace);
@@ -3212,7 +3212,7 @@ ProjectItemGroupElement filesItemGroup
32123212

32133213
// Get the required "RelPath" attribute.
32143214
string relPath = fileElement.GetAttribute(VSProjectAttributes.relPath);
3215-
ProjectErrorUtilities.VerifyThrowInvalidProject((relPath != null) && (relPath.Length > 0),
3215+
ProjectErrorUtilities.VerifyThrowInvalidProject(!string.IsNullOrEmpty(relPath),
32163216
fileElement.Location, "MissingAttribute", VSProjectAttributes.relPath, VSProjectElements.file);
32173217
// Remove the "RelPath" attribute, so we don't end up adding it twice.
32183218
fileElement.RemoveAttribute(VSProjectAttributes.relPath);
@@ -3226,7 +3226,7 @@ ProjectItemGroupElement filesItemGroup
32263226
// what the build action is based on the file extension. This is
32273227
// what the project loading code does in VS.
32283228
string buildAction = fileElement.GetAttribute(VSProjectAttributes.buildAction);
3229-
if ((buildAction == null) || (buildAction.Length == 0))
3229+
if (string.IsNullOrEmpty(buildAction))
32303230
{
32313231
buildAction = VSProjectAttributes.buildActionNone;
32323232
}
@@ -3243,7 +3243,7 @@ ProjectItemGroupElement filesItemGroup
32433243
)
32443244
{
32453245
// Add the new item to XMake.
3246-
if ((linkPath == null) || (linkPath.Length == 0))
3246+
if (string.IsNullOrEmpty(linkPath))
32473247
{
32483248
// Normal item.
32493249

@@ -3338,7 +3338,7 @@ private bool IsFilePresentButEmpty(string relPath, string linkPath)
33383338
// relpath is the filename
33393339
// linkPath, if it exists, is the relative path from the project, or the absolute full path
33403340
string path;
3341-
if (linkPath == null || linkPath.Length == 0)
3341+
if (string.IsNullOrEmpty(linkPath))
33423342
{
33433343
path = Path.Combine(Path.GetDirectoryName(oldProjectFile), relPath);
33443344
}
@@ -3401,7 +3401,7 @@ ProjectItemGroupElement filesItemGroup
34013401

34023402
// Get the required "RelPath" attribute.
34033403
string relPath = folderElement.GetAttribute(VSProjectAttributes.relPath);
3404-
ProjectErrorUtilities.VerifyThrowInvalidProject((relPath != null) && (relPath.Length > 0),
3404+
ProjectErrorUtilities.VerifyThrowInvalidProject(!string.IsNullOrEmpty(relPath),
34053405
folderElement.Location, "MissingAttribute", VSProjectAttributes.relPath, VSProjectElements.folder);
34063406
// Remove the "RelPath" attribute, so we don't end up adding it twice.
34073407
folderElement.RemoveAttribute(VSProjectAttributes.relPath);
@@ -3445,7 +3445,7 @@ ProjectItemGroupElement filesItemGroup
34453445
newFolderItem = filesItemGroup.AddItem(XMakeProjectStrings.webReferences,
34463446
ProjectCollection.Escape(relPath));
34473447
}
3448-
else if ((webReferenceUrl != null) && (webReferenceUrl.Length > 0))
3448+
else if (!string.IsNullOrEmpty(webReferenceUrl))
34493449
{
34503450
// This is an actual web reference URL.
34513451

@@ -3615,7 +3615,7 @@ ProjectItemGroupElement startupServicesItemGroup
36153615

36163616
// Get the required "ID" attribute.
36173617
string id = serviceElement.GetAttribute(VSProjectAttributes.id);
3618-
ProjectErrorUtilities.VerifyThrowInvalidProject((id != null) && (id.Length > 0), serviceElement.Location,
3618+
ProjectErrorUtilities.VerifyThrowInvalidProject(!string.IsNullOrEmpty(id), serviceElement.Location,
36193619
"MissingAttribute", VSProjectAttributes.id, VSProjectElements.service);
36203620
// Remove the "ID" attribute, so it doesn't show up in our loop later.
36213621
serviceElement.RemoveAttribute(VSProjectAttributes.id);
@@ -3814,7 +3814,7 @@ out bool isTriumphProject
38143814
if (officeDocumentPathAttribute != null)
38153815
{
38163816
string officeDocumentPath = officeDocumentPathAttribute.Value;
3817-
if ((officeDocumentPath != null) && (officeDocumentPath.Length > 0))
3817+
if (!string.IsNullOrEmpty(officeDocumentPath))
38183818
{
38193819
string projectFileDirectory = Path.GetDirectoryName(Path.GetFullPath(this.oldProjectFile));
38203820
string officeDocumentFullPath = Path.GetFullPath(Path.Combine(projectFileDirectory, officeDocumentPath));

src/Deprecated/Engine/Engine/EngineLoggingServices.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ virtual internal void LogProjectStarted(int projectId, BuildEventContext parentB
743743
ProjectStartedEventArgs e;
744744

745745

746-
if (null != targetNames && targetNames.Length > 0)
746+
if (!string.IsNullOrEmpty(targetNames))
747747
{
748748
e = new ProjectStartedEventArgs
749749
(

0 commit comments

Comments
 (0)