Skip to content

Commit

Permalink
merge some conditional expressions (#4436)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Dec 23, 2024
1 parent 9cdc9fa commit ccf922f
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public bool TryGetDotnetPathByArchitecture(
}
}

return archType is null ? throw new InvalidOperationException("Invalid image") : archType;
return archType ?? throw new InvalidOperationException("Invalid image");
}

// See https://opensource.apple.com/source/xnu/xnu-2050.18.24/EXTERNAL_HEADERS/mach-o/loader.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ internal sealed class CommandLineOptionsProxy : ICommandLineOptions
private ICommandLineOptions? _commandLineOptions;

public bool IsOptionSet(string optionName)
=> _commandLineOptions is null
? throw new InvalidOperationException(Resources.PlatformResources.CommandLineOptionsNotReady)
: _commandLineOptions.IsOptionSet(optionName);
=> _commandLineOptions?.IsOptionSet(optionName) ??
throw new InvalidOperationException(Resources.PlatformResources.CommandLineOptionsNotReady);

public bool TryGetOptionArgumentList(string optionName, [NotNullWhen(true)] out string[]? arguments)
=> _commandLineOptions is null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ await _policiesService.RegisterOnAbortCallbackAsync(
// func.
: () => _isVSTestMode || _isListTests || _isServerMode
? false
: _testHostControllerInfo.IsCurrentProcessTestHostController == null
? null
: !_testHostControllerInfo.IsCurrentProcessTestHostController;
: !_testHostControllerInfo.IsCurrentProcessTestHostController;

// This is single exe run, don't show all the details of assemblies and their summaries.
_terminalTestReporter = new TerminalTestReporter(_console, new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ public TestableAssemblyResolver(IList<string> directories)

public Func<List<string>, string, bool, Assembly> SearchAssemblySetter { get; internal set; }

protected override bool DoesDirectoryExist(string path) => DoesDirectoryExistSetter == null ? base.DoesDirectoryExist(path) : DoesDirectoryExistSetter(path);
protected override bool DoesDirectoryExist(string path) => DoesDirectoryExistSetter?.Invoke(path) ?? base.DoesDirectoryExist(path);

protected override string[] GetDirectories(string path) => GetDirectoriesSetter == null ? base.GetDirectories(path) : GetDirectoriesSetter(path);

protected override Assembly SearchAssembly(List<string> searchDirectorypaths, string name, bool isReflectionOnly) => SearchAssemblySetter == null
? base.SearchAssembly(searchDirectorypaths, name, isReflectionOnly)
: SearchAssemblySetter(searchDirectorypaths, name, isReflectionOnly);

protected override bool DoesFileExist(string filePath) => DoesFileExistSetter == null ? base.DoesFileExist(filePath) : DoesFileExistSetter(filePath);
protected override bool DoesFileExist(string filePath) => DoesFileExistSetter?.Invoke(filePath) ?? base.DoesFileExist(filePath);

protected override Assembly LoadAssemblyFrom(string path) => LoadAssemblyFromSetter == null ? base.LoadAssemblyFrom(path) : LoadAssemblyFromSetter(path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public TestableMSTestAdapterSettings()

public Func<string, string> ExpandEnvironmentVariablesSetter { get; set; }

protected override bool DoesDirectoryExist(string path) => DoesDirectoryExistSetter == null ? base.DoesDirectoryExist(path) : DoesDirectoryExistSetter(path);
protected override bool DoesDirectoryExist(string path) => DoesDirectoryExistSetter?.Invoke(path) ?? base.DoesDirectoryExist(path);

protected override string ExpandEnvironmentVariables(string path) => ExpandEnvironmentVariablesSetter == null ? base.ExpandEnvironmentVariables(path) : ExpandEnvironmentVariablesSetter(path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ private static void CustomAssert(Type type, object instanceDeserialized, object
}

public static string? FormatSerializerTypes(MethodInfo methodInfo, object?[]? data)
=> data is not null
? (data[0] as Type)?.Name
: null;
=> (data?[0] as Type)?.Name;

private static void AssertSerialize(Type type, string instanceSerialized)
{
Expand Down

0 comments on commit ccf922f

Please sign in to comment.