Skip to content

Commit 1fd59bb

Browse files
Fixup most warnings/info items
1 parent 597ef17 commit 1fd59bb

File tree

14 files changed

+36
-26
lines changed

14 files changed

+36
-26
lines changed

CodeConverter/Shared/NameGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private static void EnsureUniquenessInPlace(
6767
Func<string, bool> canUse,
6868
bool isCaseSensitive = true)
6969
{
70-
canUse = canUse ?? (s => true);
70+
canUse ??= (s => true);
7171

7272
// Don't enumerate as we will be modifying the collection in place.
7373
for (var i = 0; i < names.Count; i++) {

CodeConverter/Shared/ProjectConversion.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private ProjectConversion(IProjectContentsConverter projectContentsConverter, IE
4040

4141
public static async Task<ConversionResult> ConvertText<TLanguageConversion>(string text, TextConversionOptions conversionOptions, IProgress<ConversionProgress> progress = null, CancellationToken cancellationToken = default) where TLanguageConversion : ILanguageConversion, new()
4242
{
43-
progress = progress ?? new Progress<ConversionProgress>();
43+
progress ??= new Progress<ConversionProgress>();
4444
using var roslynEntryPoint = await RoslynEntryPoint(progress);
4545

4646
var languageConversion = new TLanguageConversion { ConversionOptions = conversionOptions };
@@ -52,7 +52,7 @@ private ProjectConversion(IProjectContentsConverter projectContentsConverter, IE
5252

5353
public static async Task<ConversionResult> ConvertSingle<TLanguageConversion>(Document document, SingleConversionOptions conversionOptions, IProgress<ConversionProgress> progress = null, CancellationToken cancellationToken = default) where TLanguageConversion : ILanguageConversion, new()
5454
{
55-
progress = progress ?? new Progress<ConversionProgress>();
55+
progress ??= new Progress<ConversionProgress>();
5656
using var roslynEntryPoint = await RoslynEntryPoint(progress);
5757

5858
var languageConversion = new TLanguageConversion { ConversionOptions = conversionOptions };
@@ -68,10 +68,10 @@ private ProjectConversion(IProjectContentsConverter projectContentsConverter, IE
6868

6969
var conversion = new ProjectConversion(projectContentsConverter, new[] { document }, Enumerable.Empty<TextDocument>(), languageConversion, cancellationToken, conversionOptions.ShowCompilationErrors, returnSelectedNode);
7070
var conversionResults = await conversion.Convert(progress).ToArrayAsync();
71-
return GetSingleResultForDocument(conversionResults, document, progress);
71+
return GetSingleResultForDocument(conversionResults, document);
7272
}
7373

74-
private static ConversionResult GetSingleResultForDocument(ConversionResult[] conversionResults, Document document, IProgress<ConversionProgress> progress)
74+
private static ConversionResult GetSingleResultForDocument(ConversionResult[] conversionResults, Document document)
7575
{
7676
var codeResult = conversionResults.First(r => r.SourcePathOrNull == document.FilePath);
7777
codeResult.Exceptions = conversionResults.SelectMany(x => x.Exceptions).ToArray();
@@ -82,7 +82,7 @@ public static async IAsyncEnumerable<ConversionResult> ConvertProject(Project pr
8282
ILanguageConversion languageConversion, IProgress<ConversionProgress> progress, [EnumeratorCancellation] CancellationToken cancellationToken,
8383
params (string Find, string Replace, bool FirstOnly)[] replacements)
8484
{
85-
progress = progress ?? new Progress<ConversionProgress>();
85+
progress ??= new Progress<ConversionProgress>();
8686
using var roslynEntryPoint = await RoslynEntryPoint(progress);
8787

8888
var projectContentsConverter = await languageConversion.CreateProjectContentsConverter(project, progress, cancellationToken);

CodeConverter/Shared/TextReplacementConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static class TextReplacementConverter
99
{
1010
public static ConversionResult ConversionResultFromReplacements(this FileInfo filePath, IEnumerable<(string Find, string Replace, bool FirstOnly)> replacements, Func<string, string> postReplacementTransform = null)
1111
{
12-
postReplacementTransform = postReplacementTransform ?? (s => s);
12+
postReplacementTransform ??= (s => s);
1313
var newProjectText = File.ReadAllText(filePath.FullName);
1414
newProjectText = newProjectText.Replace(replacements);
1515
string withReplacements = postReplacementTransform(newProjectText);

CodeConverter/Util/FromRoslyn/SpecializedCollections.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static ISet<T> ReadOnlySet<T>(IEnumerable<T> values)
9191

9292
HashSet<T> result = null;
9393
foreach (var item in values) {
94-
result = result ?? new HashSet<T>();
94+
result ??= new HashSet<T>();
9595
result.Add(item);
9696
}
9797

CodeConverter/Util/ISymbolExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static bool IsDefinedInSource(this ISymbol symbol)
2323

2424
public static TSymbol ExtractBestMatch<TSymbol>(this SymbolInfo info, Func<TSymbol, bool> isMatch = null) where TSymbol : class, ISymbol
2525
{
26-
isMatch = isMatch ?? (_ => true);
26+
isMatch ??= (_ => true);
2727
if (info.Symbol == null && info.CandidateSymbols.Length == 0)
2828
return null;
2929
if (info.Symbol != null)

CodeConverter/Util/SyntaxNodeExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public static T WithConvertedTrailingTriviaFrom<T>(this T node, SyntaxToken from
339339

340340
public static SyntaxToken WithConvertedTrailingTriviaFrom(this SyntaxToken node, SyntaxToken? otherToken, TriviaKinds triviaKinds = null)
341341
{
342-
triviaKinds = triviaKinds ?? TriviaKinds.All;
342+
triviaKinds ??= TriviaKinds.All;
343343
if (!otherToken.HasValue || !otherToken.Value.HasTrailingTrivia) return node;
344344
var convertedTrivia = ConvertTrivia(otherToken.Value.TrailingTrivia.Where(triviaKinds.ShouldAccept).ToArray());
345345
return node.WithTrailingTrivia(node.ImportantTrailingTrivia().Concat(convertedTrivia));

CodeConverter/Util/TypeExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static string GetFullMetadataName(this INamedTypeSymbol symbol)
9292

9393
public static string GetFullMetadataName(this INamespaceSymbol ns, StringBuilder sb = null)
9494
{
95-
sb = sb ?? new StringBuilder();
95+
sb ??= new StringBuilder();
9696
while (ns != null && !ns.IsGlobalNamespace) {
9797
if (sb.Length > 0) sb.Insert(0, '.');
9898
sb.Insert(0, ns.MetadataName);

CommandLine/CodeConv.Shared/CodeConvProgram.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public partial class CodeConvProgram
3333
/// <remarks>Calls <see cref="OnExecuteAsync(CommandLineApplication)"/> by reflection</remarks>
3434
public static async Task<int> Main(string[] args) => await CommandLineApplication.ExecuteAsync<CodeConvProgram>(args);
3535
/// <remarks>Used by reflection in CommandLineApplication.ExecuteAsync</remarks>
36-
private async Task<int> OnExecuteAsync(CommandLineApplication app) => await ExecuteAsync();
36+
private async Task<int> OnExecuteAsync(CommandLineApplication _) => await ExecuteAsync();
3737

3838
[FileExists]
3939
[Required]
@@ -88,8 +88,8 @@ private async Task<int> ExecuteAsync()
8888

8989
if (!(ex is ValidationException)) {
9090
await Console.Error.WriteLineAsync(Environment.NewLine + ex.GetType() + ex.StackTrace);
91-
if (ex is ReflectionTypeLoadException rtle) {
92-
foreach (var e in rtle.LoaderExceptions) {
91+
if (ex is ReflectionTypeLoadException rtle && rtle.LoaderExceptions is IEnumerable<Exception> loaderExceptions) {
92+
foreach (var e in loaderExceptions) {
9393
await Console.Error.WriteLineAsync(e.Message);
9494
}
9595
}
@@ -168,7 +168,7 @@ private bool ShouldIncludeProject(Project project)
168168
var vsWhereExe = Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe");
169169
var args = new[] { "-latest", "-prerelease", "-products", "*", "-requires", "Microsoft.Component.MSBuild", "-version", "[16.0,]", "-find", @"MSBuild\**\Bin\MSBuild.exe" };
170170

171-
var (exitCode, stdOut, stdErr) = await new ProcessStartInfo(vsWhereExe) {
171+
var (exitCode, stdOut, _) = await new ProcessStartInfo(vsWhereExe) {
172172
Arguments = ArgumentEscaper.EscapeAndConcatenate(args)
173173
}.GetOutputAsync();
174174

CommandLine/CodeConv.Shared/ConversionResultWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ICSharpCode.CodeConverter.CommandLine
1111
{
1212
public static class ConversionResultWriter
1313
{
14-
private static string[] FileSystemNamesToIgnore = new[] { ".git", ".gitattributes", ".gitignore", "bin", "obj", ".vs" };
14+
private static readonly string[] FileSystemNamesToIgnore = new[] { ".git", ".gitattributes", ".gitignore", "bin", "obj", ".vs" };
1515

1616
public static async Task WriteConvertedAsync(IAsyncEnumerable<ConversionResult> conversionResultsEnumerable, string solutionFilePath, DirectoryInfo targetDirectory, bool wipeTargetDirectory, bool copyOriginalDirectory, IProgress<string> progress, CancellationToken cancellationToken)
1717
{

CommandLine/CodeConv.Shared/Util/AppDomainExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ internal static class AppDomainExtensions
77
{
88
public static void UseVersionAgnosticAssemblyResolution(this AppDomain appDomain) => appDomain.AssemblyResolve += LoadAnyVersion;
99

10-
private static Assembly? LoadAnyVersion(object sender, ResolveEventArgs args)
10+
private static Assembly? LoadAnyVersion(object? sender, ResolveEventArgs? args)
1111
{
12+
if (args?.Name == null) return null;
1213
var requestedAssemblyName = new AssemblyName(args.Name);
13-
if (requestedAssemblyName.Version != null) {
14+
if (requestedAssemblyName.Version != null && requestedAssemblyName.Name != null) {
1415
try {
1516
return Assembly.Load(new AssemblyName(requestedAssemblyName.Name) { CultureName = requestedAssemblyName.CultureName });
1617
} catch (Exception) {

0 commit comments

Comments
 (0)