C#: Add sealed modifier to classes to fix dispose-pattern, remove explicit IDisposable implementations

This commit is contained in:
Tamas Vajk 2020-10-02 11:49:35 +02:00
Родитель 397be7e98f
Коммит e73ced2275
13 изменённых файлов: 23 добавлений и 22 удалений

Просмотреть файл

@ -12,7 +12,7 @@ namespace Semmle.Extraction.CIL
/// Adds additional context that is specific for CIL extraction.
/// One context = one DLL/EXE.
/// </summary>
partial class Context : IDisposable
sealed partial class Context : IDisposable
{
readonly FileStream stream;
Entities.Assembly? assemblyNull;
@ -58,7 +58,7 @@ namespace Semmle.Extraction.CIL
}
}
void IDisposable.Dispose()
public void Dispose()
{
if (pdb != null)
pdb.Dispose();

Просмотреть файл

@ -9,7 +9,7 @@ namespace Semmle.Extraction.CIL
/// <summary>
/// Provides methods for creating and caching various entities.
/// </summary>
public partial class Context
public sealed partial class Context
{
readonly Dictionary<object, Label> ids = new Dictionary<object, Label>();

Просмотреть файл

@ -13,7 +13,7 @@ namespace Semmle.Extraction.PDB
///
/// PDB information can be in a separate PDB file, or embedded in the DLL.
/// </summary>
class MetadataPdbReader : IPdb
sealed class MetadataPdbReader : IPdb
{
class SourceFile : ISourceFile
{

Просмотреть файл

@ -14,7 +14,7 @@ namespace Semmle.Extraction.PDB
/// A PDB reader using Microsoft.DiaSymReader.Native.
/// This is an unmanaged Windows DLL, which therefore only works on Windows.
/// </summary>
class NativePdbReader : IPdb
sealed class NativePdbReader : IPdb
{
sealed class Document : ISourceFile
{

Просмотреть файл

@ -46,7 +46,7 @@ namespace Semmle.BuildAnalyser
/// <summary>
/// Main implementation of the build analysis.
/// </summary>
class BuildAnalysis : IBuildAnalysis, IDisposable
sealed class BuildAnalysis : IBuildAnalysis, IDisposable
{
private readonly AssemblyCache assemblyCache;
private readonly IProgressMonitor progressMonitor;

Просмотреть файл

@ -22,7 +22,7 @@ namespace Semmle.Extraction.CSharp.Standalone
/// <summary>
/// Searches for source/references and creates separate extractions.
/// </summary>
class Analysis : IDisposable
sealed class Analysis : IDisposable
{
public Analysis(ILogger logger, Options options)
{

Просмотреть файл

@ -15,7 +15,7 @@ namespace Semmle.Extraction.CSharp
/// <summary>
/// Encapsulates a C# analysis task.
/// </summary>
public class Analyser : IDisposable
public sealed class Analyser : IDisposable
{
IExtractor extractor;

Просмотреть файл

@ -199,7 +199,7 @@ namespace Semmle.Extraction.Tests
new Semmle.Extraction.Layout(null, null, "layout.txt"));
}
class LoggerMock : ILogger
sealed class LoggerMock : ILogger
{
public void Dispose() { }

Просмотреть файл

@ -42,7 +42,7 @@ namespace Semmle.Extraction.Tests
Assert.Equal(@"C:\Temp\source_archive\diskstation\share\source\def.cs", TrapWriter.NestPaths(logger, @"C:\Temp\source_archive", $@"{root3}{root3}diskstation\share\source\def.cs").Replace('/', '\\'));
}
class LoggerMock : ILogger
sealed class LoggerMock : ILogger
{
public void Dispose() { }

Просмотреть файл

@ -283,7 +283,7 @@ namespace Semmle.Extraction
public IDisposable StackGuard => new ScopeGuard(this);
private class ScopeGuard : IDisposable
private sealed class ScopeGuard : IDisposable
{
readonly Context cx;

Просмотреть файл

@ -6,7 +6,7 @@ using System;
namespace SemmleTests.Semmle.Util
{
public class CanonicalPathCacheTest : IDisposable
public sealed class CanonicalPathCacheTest : IDisposable
{
readonly ILogger Logger = new LoggerMock();
readonly string root;
@ -24,9 +24,10 @@ namespace SemmleTests.Semmle.Util
root = Win32.IsWindows() ? @"X:\" : "/";
}
void IDisposable.Dispose()
public void Dispose()
{
File.Delete("abc");
Logger.Dispose();
}
[Fact]
@ -172,7 +173,7 @@ namespace SemmleTests.Semmle.Util
CanonicalPathDots();
}
class LoggerMock : ILogger
sealed class LoggerMock : ILogger
{
public void Dispose() { }

Просмотреть файл

@ -10,20 +10,20 @@ namespace SemmleTests.Semmle.Util
/// Ensure that the Extractor works with long paths.
/// These should be handled by .NET Core.
/// </summary>
public class LongPaths : IDisposable
public sealed class LongPaths : IDisposable
{
static readonly string tmpDir = Path.GetTempPath();
static readonly string shortPath = Path.Combine(tmpDir, "test.txt");
static readonly string longPath = Path.Combine(tmpDir, "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"ccccccccccccccccccccccccccccccc", "ddddddddddddddddddddddddddddddddddddd", "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "fffffffffffffffffffffffffffffffff",
"ggggggggggggggggggggggggggggggggggg","hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh","iiiiiiiiiiiiiiii.txt");
"ggggggggggggggggggggggggggggggggggg", "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", "iiiiiiiiiiiiiiii.txt");
public LongPaths()
{
CleanUp();
}
void IDisposable.Dispose()
public void Dispose()
{
CleanUp();
}
@ -34,14 +34,14 @@ namespace SemmleTests.Semmle.Util
{
File.Delete(shortPath);
}
catch(DirectoryNotFoundException)
catch (DirectoryNotFoundException)
{
}
try
{
File.Delete(longPath);
}
catch(DirectoryNotFoundException)
catch (DirectoryNotFoundException)
{
}
}

Просмотреть файл

@ -55,7 +55,7 @@ namespace Semmle.Util.Logging
/// A logger that outputs to a <code>csharp.log</code>
/// file.
/// </summary>
public class FileLogger : ILogger
public sealed class FileLogger : ILogger
{
readonly StreamWriter writer;
readonly Verbosity verbosity;
@ -100,7 +100,7 @@ namespace Semmle.Util.Logging
/// <summary>
/// A logger that outputs to stdout/stderr.
/// </summary>
public class ConsoleLogger : ILogger
public sealed class ConsoleLogger : ILogger
{
readonly Verbosity verbosity;
@ -143,7 +143,7 @@ namespace Semmle.Util.Logging
/// <summary>
/// A combined logger.
/// </summary>
public class CombinedLogger : ILogger
public sealed class CombinedLogger : ILogger
{
readonly ILogger logger1;
readonly ILogger logger2;