dotnet / dotnet/msbuild

Avoid DirectorySeparatorChar.ToString()

Open
#3,544 0 comments 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

These codepaths all allocate a string unnecessarily. `EndsWith(char)` is not available in .NET Framework but they could meantime be replaced with something like FileUtilities.EnsureTrailingSlash. Note that some check for AltDirectorySeparatorChar and some do not though.

```
C:\git\msbuild\src\Build\Construction\Solution\SolutionProjectGenerator.cs:
2198: if (!directoryName.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))

C:\git\msbuild\src\Shared\FrameworkLocationHelper.cs:
487 FallbackDotNetFrameworkSdkInstallPath.EndsWith(
488: Path.DirectorySeparatorChar.ToString(),
489 StringComparison.Ordinal);
...
960: var endedWithASlash = path.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)
961 || path.EndsWith(
962 Path.AltDirectorySeparatorChar.ToString(),

C:\git\msbuild\src\Utilities\ToolLocationHelper.cs:
2114 !dotNetFrameworkReferenceAssemblies[i].EndsWith(
2115: Path.DirectorySeparatorChar.ToString(),
2116 StringComparison.Ordinal))
```

Most likely this is more tidiness than any measurable perf impact.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.