Skip to content

Commit 5cda4f4

Browse files
authored
use some NotNullWhen on TryGets (#4520)
1 parent fcd3ef5 commit 5cda4f4

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Collections.ObjectModel;
7+
using System.Diagnostics.CodeAnalysis;
78
using System.Globalization;
89
using System.Linq;
910

@@ -387,7 +388,7 @@ private void CleanupPlugins()
387388
/// <param name="friendlyName">The friendly Name.</param>
388389
/// <param name="dataCollectorUri">The data collector Uri.</param>
389390
/// <returns><see cref="bool"/></returns>
390-
protected virtual bool TryGetUriFromFriendlyName(string? friendlyName, out string? dataCollectorUri)
391+
protected virtual bool TryGetUriFromFriendlyName(string? friendlyName, [NotNullWhen(true)] out string? dataCollectorUri)
391392
{
392393
TPDebug.Assert(_dataCollectorExtensionManager is not null, "_dataCollectorExtensionManager is null");
393394
foreach (var extension in _dataCollectorExtensionManager.TestExtensions)

src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,13 @@ public string GetMonoPath()
9696
return monoPath;
9797
}
9898

99-
private bool TryGetExecutablePath(string executableBaseName, out string executablePath)
99+
private bool TryGetExecutablePath(string executableBaseName, [NotNullWhen(true)] out string? executablePath)
100100
{
101101
if (_environment.OperatingSystem.Equals(PlatformOperatingSystem.Windows))
102102
{
103103
executableBaseName += ".exe";
104104
}
105105

106-
executablePath = string.Empty;
107106
var pathString = Environment.GetEnvironmentVariable("PATH")!;
108107
foreach (string path in pathString.Split(Path.PathSeparator))
109108
{
@@ -115,6 +114,7 @@ private bool TryGetExecutablePath(string executableBaseName, out string executab
115114
}
116115
}
117116

117+
executablePath = null;
118118
return false;
119119
}
120120

src/Microsoft.TestPlatform.CrossPlatEngine/Client/TestLoggerManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Globalization;
78
using System.Linq;
89
using System.Reflection;
@@ -387,7 +388,7 @@ internal bool InitializeLoggerByUri(Uri uri, Dictionary<string, string?>? parame
387388
/// <param name="friendlyName">The friendly Name.</param>
388389
/// <param name="loggerUri">The logger Uri.</param>
389390
/// <returns><see cref="bool"/></returns>
390-
internal bool TryGetUriFromFriendlyName(string? friendlyName, out Uri? loggerUri)
391+
internal bool TryGetUriFromFriendlyName(string? friendlyName, [NotNullWhen(true)] out Uri? loggerUri)
391392
{
392393
var extensionManager = TestLoggerExtensionManager;
393394
foreach (var extension in extensionManager.TestExtensions)

0 commit comments

Comments
 (0)