C#: Fix quality issues

This commit is contained in:
Tamas Vajk
2024-06-28 11:09:40 +02:00
parent 1cf5e89b96
commit 199a9688af
47 changed files with 79 additions and 85 deletions

View File

@@ -37,7 +37,7 @@ namespace Semmle.Extraction
// A recursion guard against writing to the trap file whilst writing an id to the trap file.
private bool writingLabel = false;
private readonly Queue<IEntity> labelQueue = new();
private readonly Queue<IEntity> labelQueue = [];
protected void DefineLabel(IEntity entity)
{

View File

@@ -56,7 +56,7 @@ namespace Semmle.Extraction
default:
wrapped.Write(c);
break;
};
}
}
public void WriteSubId(IEntity entity)

View File

@@ -65,7 +65,7 @@ namespace Semmle.Extraction
// Roslyn framework has no apparent mechanism to associate assemblies with their files.
// So this lookup table needs to be populated.
private readonly Dictionary<string, string> referenceFilenames = new Dictionary<string, string>();
private readonly Dictionary<string, string> referenceFilenames = [];
public void SetAssemblyFile(string assembly, string file)
{

View File

@@ -125,7 +125,7 @@ namespace Semmle.Extraction
if (!Valid)
throw new InvalidOperationException("Attempt to use an invalid label");
return "#" + Value;
return $"#{Value}";
}
public static bool operator ==(Label l1, Label l2) => l1.Value == l2.Value;

View File

@@ -92,7 +92,7 @@ namespace Semmle.Extraction
{
var ret = value;
if (ret.Length >= 2 && ret[1] == ':' && Char.IsLower(ret[0]))
ret = Char.ToUpper(ret[0]) + "_" + ret.Substring(2);
ret = $"{char.ToUpper(ret[0])}_{ret[2..]}";
return ret.Replace('\\', '/').Replace(":", "_");
}
}

View File

@@ -48,7 +48,7 @@ namespace Semmle.Extraction
writerLazy = new Lazy<StreamWriter>(() =>
{
var tempPath = trap ?? FileUtils.GetTemporaryWorkingDirectory(out var _);
var tempPath = trap ?? FileUtils.GetTemporaryWorkingDirectory(out _);
do
{
@@ -139,7 +139,7 @@ namespace Semmle.Extraction
// - the same file was compiled multiple times, or
// - the file doesn't exist (due to wrong #line directive or because it's an in-memory source generated AST).
// In any case, this is not a fatal error.
logger.LogWarning("Problem archiving " + dest + ": " + ex);
logger.LogWarning($"Problem archiving {dest}: {ex}");
}
}