Skip to content

Commit

Permalink
use some NotNullWhen on TryGets (#4520)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Jun 6, 2023
1 parent fcd3ef5 commit 5cda4f4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;

Expand Down Expand Up @@ -387,7 +388,7 @@ private void CleanupPlugins()
/// <param name="friendlyName">The friendly Name.</param>
/// <param name="dataCollectorUri">The data collector Uri.</param>
/// <returns><see cref="bool"/></returns>
protected virtual bool TryGetUriFromFriendlyName(string? friendlyName, out string? dataCollectorUri)
protected virtual bool TryGetUriFromFriendlyName(string? friendlyName, [NotNullWhen(true)] out string? dataCollectorUri)
{
TPDebug.Assert(_dataCollectorExtensionManager is not null, "_dataCollectorExtensionManager is null");
foreach (var extension in _dataCollectorExtensionManager.TestExtensions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@ public string GetMonoPath()
return monoPath;
}

private bool TryGetExecutablePath(string executableBaseName, out string executablePath)
private bool TryGetExecutablePath(string executableBaseName, [NotNullWhen(true)] out string? executablePath)
{
if (_environment.OperatingSystem.Equals(PlatformOperatingSystem.Windows))
{
executableBaseName += ".exe";
}

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

executablePath = null;
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -387,7 +388,7 @@ internal bool InitializeLoggerByUri(Uri uri, Dictionary<string, string?>? parame
/// <param name="friendlyName">The friendly Name.</param>
/// <param name="loggerUri">The logger Uri.</param>
/// <returns><see cref="bool"/></returns>
internal bool TryGetUriFromFriendlyName(string? friendlyName, out Uri? loggerUri)
internal bool TryGetUriFromFriendlyName(string? friendlyName, [NotNullWhen(true)] out Uri? loggerUri)
{
var extensionManager = TestLoggerExtensionManager;
foreach (var extension in extensionManager.TestExtensions)
Expand Down

0 comments on commit 5cda4f4

Please sign in to comment.