diff --git a/Common.ruleset b/Common.ruleset index a842f23d7c..640e31b866 100644 --- a/Common.ruleset +++ b/Common.ruleset @@ -16,6 +16,12 @@ + + + + + + diff --git a/ExternalProjects/BizHawk.Analyzer/RoslynUtils.cs b/ExternalProjects/BizHawk.Analyzer/RoslynUtils.cs index 2a7ffbf43e..5ee6e2f865 100644 --- a/ExternalProjects/BizHawk.Analyzer/RoslynUtils.cs +++ b/ExternalProjects/BizHawk.Analyzer/RoslynUtils.cs @@ -1,10 +1,18 @@ namespace BizHawk.Analyzers; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; internal static class RoslynUtils { + public static SyntaxNode? EnclosingTypeDeclarationSyntax(this CSharpSyntaxNode node) + { + var parent = node.Parent; + while (parent is not (null or TypeDeclarationSyntax)) parent = parent.Parent; + return parent; + } + private static ITypeSymbol? GetThrownExceptionType(this SemanticModel model, ExpressionSyntax exprSyn) => exprSyn is ObjectCreationExpressionSyntax ? model.GetTypeInfo(exprSyn).Type @@ -16,6 +24,6 @@ internal static class RoslynUtils public static ITypeSymbol? GetThrownExceptionType(this SemanticModel model, ThrowStatementSyntax tss) => model.GetThrownExceptionType(tss.Expression!); - public static bool Matches(this ITypeSymbol expected, ITypeSymbol? actual) + public static bool Matches(this ISymbol expected, ISymbol? actual) => SymbolEqualityComparer.Default.Equals(expected, actual); } diff --git a/ExternalProjects/BizHawk.Analyzer/UseTypeofOperatorAnalyzer.cs b/ExternalProjects/BizHawk.Analyzer/UseTypeofOperatorAnalyzer.cs new file mode 100644 index 0000000000..93ed858abd --- /dev/null +++ b/ExternalProjects/BizHawk.Analyzer/UseTypeofOperatorAnalyzer.cs @@ -0,0 +1,50 @@ +namespace BizHawk.Analyzers; + +using System.Collections.Immutable; + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Operations; + +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public sealed class UseTypeofOperatorAnalyzer : DiagnosticAnalyzer +{ + private static readonly DiagnosticDescriptor DiagNoGetTypeOnThis = new( + id: "BHI1101", + title: "Don't call this.GetType(), use typeof operator (or replace subtype check with better encapsulation)", + messageFormat: "Replace this.GetType() with typeof({0}) (or replace subtype check with better encapsulation)", + category: "Usage", + defaultSeverity: DiagnosticSeverity.Warning, + isEnabledByDefault: true); + + private static readonly DiagnosticDescriptor DiagNoGetTypeOnThisSealed = new( + id: "BHI1100", + title: "Don't call this.GetType() in sealed type, use typeof operator", + messageFormat: "Replace this.GetType() with typeof({0})", + category: "Usage", + defaultSeverity: DiagnosticSeverity.Error, + isEnabledByDefault: true); + + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(DiagNoGetTypeOnThisSealed, DiagNoGetTypeOnThis); + + public override void Initialize(AnalysisContext context) + { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); + context.EnableConcurrentExecution(); + ISymbol? objectDotGetTypeSym = null; + context.RegisterOperationAction( + oac => + { + var operation = (IInvocationOperation) oac.Operation; + if (operation.IsImplicit || operation.Instance is null) return; + objectDotGetTypeSym ??= oac.Compilation.GetTypeByMetadataName("System.Object")!.GetMembers("GetType")[0]; + if (!objectDotGetTypeSym.Matches(operation.TargetMethod)) return; + if (operation.Instance.Syntax is not ThisExpressionSyntax and not IdentifierNameSyntax { Identifier.Text: "GetType" }) return; // called on something that isn't `this` + var enclosingType = operation.SemanticModel.GetDeclaredSymbol(((CSharpSyntaxNode) operation.Syntax).EnclosingTypeDeclarationSyntax()!)!; + oac.ReportDiagnostic(Diagnostic.Create(enclosingType.IsSealed ? DiagNoGetTypeOnThisSealed : DiagNoGetTypeOnThis, operation.Syntax.GetLocation(), enclosingType.Name)); + }, + OperationKind.Invocation); + } +} diff --git a/References/BizHawk.Analyzer.dll b/References/BizHawk.Analyzer.dll index 4fe37a0909..cfa7f15ff0 100644 Binary files a/References/BizHawk.Analyzer.dll and b/References/BizHawk.Analyzer.dll differ diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Datacorder/DatacorderDevice.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Datacorder/DatacorderDevice.cs index 070b9869de..5343e0740b 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Datacorder/DatacorderDevice.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Datacorder/DatacorderDevice.cs @@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC /// /// Represents the tape device /// - public class DatacorderDevice + public sealed class DatacorderDevice { private CPCBase _machine; private Z80A _cpu => _machine.CPU; @@ -348,7 +348,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC { // exception during operation var e = ex; - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(DatacorderDevice).ToString() + "\n\nTape image file has a valid CDT header, but threw an exception whilst data was being parsed.\n\n" + e.ToString()); } } diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Disk/NECUPD765.FDD.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Disk/NECUPD765.FDD.cs index 326992a5af..5375997144 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Disk/NECUPD765.FDD.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Disk/NECUPD765.FDD.cs @@ -170,7 +170,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC /// /// Holds specfic state information about a drive /// - private class DriveState : IFDDHost + private sealed class DriveState : IFDDHost { /// /// The drive ID from an FDC perspective @@ -775,7 +775,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC if (!found) { - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(DriveState).ToString() + "\n\nDisk image file could not be parsed. Potentially an unknown format."); } } diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Media.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Media.cs index cc94b70c6d..1d091c2c30 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Media.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Media.cs @@ -214,7 +214,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC /// protected void LoadDiskMedia() { - if (this.GetType() == typeof(CPC464)) + if (this is CPC464) { CPC.CoreComm.ShowMessage("You are trying to load one of more disk images.\n\n Please select something other than CPC 464 emulation immediately and reboot the core"); return; diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/MediaConverter.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/MediaConverter.cs index 894930e5a2..48f8ce7e2b 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/MediaConverter.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/MediaConverter.cs @@ -24,12 +24,14 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC /// public virtual bool IsWriter => false; + protected abstract Type SelfType { get; } + /// /// Serialization method /// public virtual void Read(byte[] data) { - throw new NotImplementedException(this.GetType() + + throw new NotImplementedException(SelfType + "Read operation is not implemented for this converter"); } @@ -38,7 +40,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC /// public virtual void Write(byte[] data) { - throw new NotImplementedException(this.GetType() + + throw new NotImplementedException(SelfType + "Write operation is not implemented for this converter"); } @@ -47,7 +49,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC /// public virtual bool CheckType(byte[] data) { - throw new NotImplementedException(this.GetType().ToString() + + throw new NotImplementedException(SelfType.ToString() + "Check type operation is not implemented for this converter"); } diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Tape/CDT/CdtConverter.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Tape/CDT/CdtConverter.cs index 60ead4776b..2e803041b1 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Tape/CDT/CdtConverter.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Tape/CDT/CdtConverter.cs @@ -8,7 +8,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC /// /// Responsible for TZX format serialization /// - public class CdtConverter : MediaConverter + public sealed class CdtConverter : MediaConverter { /// /// The type of serializer @@ -26,6 +26,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC /// public override bool IsWriter => false; + protected override Type SelfType + => typeof(CdtConverter); + /// /// Working list of generated tape data blocks /// @@ -164,7 +167,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC if (ident != "ZXTape!" || eotm != 0x1A) { // this is not a valid TZX format file - throw new Exception(this.GetType() + + throw new Exception(typeof(CdtConverter) + "This is not a valid TZX format file"); } diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs index bd00c81079..37e225e404 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs @@ -11,7 +11,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// Represents the tape device (or build-in datacorder as it was called +2 and above) /// - public class DatacorderDevice : IPortIODevice + public sealed class DatacorderDevice : IPortIODevice { private SpectrumBase _machine { get; set; } private Z80A _cpu { get; set; } @@ -312,7 +312,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { // exception during operation var e = ex; - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(DatacorderDevice).ToString() + "\n\nTape image file has a valid TZX header, but threw an exception whilst data was being parsed.\n\n" + e.ToString()); } } @@ -332,7 +332,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { // exception during operation var e = ex; - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(DatacorderDevice).ToString() + "\n\nTape image file has a valid PZX header, but threw an exception whilst data was being parsed.\n\n" + e.ToString()); } } @@ -352,7 +352,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { // exception during operation var e = ex; - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(DatacorderDevice).ToString() + "\n\nTape image file has a valid CSW header, but threw an exception whilst data was being parsed.\n\n" + e.ToString()); } } @@ -372,7 +372,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { // exception during operation var e = ex; - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(DatacorderDevice).ToString() + "\n\nTape image file has a valid WAV header, but threw an exception whilst data was being parsed.\n\n" + e.ToString()); } } @@ -391,7 +391,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { // exception during operation var e = ex; - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(DatacorderDevice).ToString() + "\n\nAn exception was thrown whilst data from this tape image was being parsed as TAP.\n\n" + e.ToString()); } } diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDD.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDD.cs index 3912f22ba0..c4aee7d40a 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDD.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDD.cs @@ -170,7 +170,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// Holds specfic state information about a drive /// - private class DriveState : IFDDHost + private sealed class DriveState : IFDDHost { /// /// The drive ID from an FDC perspective @@ -776,7 +776,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum if (!found) { - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(DriveState).ToString() + "\n\nDisk image file could not be parsed. Potentially an unknown format."); } } diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs index 954b605707..a39b02a0e3 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs @@ -227,7 +227,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// protected void LoadDiskMedia() { - if (this.GetType() != typeof(ZX128Plus3)) + if (this is not ZX128Plus3) { Spectrum.CoreComm.ShowMessage("You are trying to load one of more disk images.\n\n Please select ZX Spectrum +3 emulation immediately and reboot the core"); return; diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Memory.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Memory.cs index d15a59f528..1e00b12393 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Memory.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Memory.cs @@ -157,16 +157,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// Detects whether this is a 48k machine (or a 128k in 48k mode) /// public virtual bool IsIn48kMode() - { - if (this.GetType() == typeof(ZX48) || - this.GetType() == typeof(ZX16) || - PagingDisabled) - { - return true; - } - else - return false; - } + => PagingDisabled || this is ZX48 or ZX16; /// /// Monitors ROM access diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/MediaConverter.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/MediaConverter.cs index 22f7dd9f3d..5425fd46f1 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/MediaConverter.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/MediaConverter.cs @@ -26,12 +26,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public virtual bool IsWriter => false; + protected abstract Type SelfType { get; } + /// /// Serialization method /// public virtual void Read(byte[] data) { - throw new NotImplementedException(this.GetType().ToString() + + throw new NotImplementedException(SelfType.ToString() + "Read operation is not implemented for this converter"); } @@ -40,7 +42,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public virtual void Write(byte[] data) { - throw new NotImplementedException(this.GetType().ToString() + + throw new NotImplementedException(SelfType.ToString() + "Write operation is not implemented for this converter"); } @@ -49,7 +51,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public virtual bool CheckType(byte[] data) { - throw new NotImplementedException(this.GetType().ToString() + + throw new NotImplementedException(SelfType.ToString() + "Check type operation is not implemented for this converter"); } diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/CSW/CswConverter.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/CSW/CswConverter.cs index 22f2cc4fd2..97429ef4e1 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/CSW/CswConverter.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/CSW/CswConverter.cs @@ -9,7 +9,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// Responsible for Compressed Square Wave conversion /// https://web.archive.org/web/20171024182530/http://ramsoft.bbk.org.omegahg.com/csw.html /// - public class CswConverter : MediaConverter + public sealed class CswConverter : MediaConverter { /// /// The type of serializer @@ -32,6 +32,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public override bool IsWriter => false; + protected override Type SelfType + => typeof(CswConverter); + private readonly DatacorderDevice _datacorder; public CswConverter(DatacorderDevice _tapeDevice) @@ -80,14 +83,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum if (ident.ToUpper() != "COMPRESSED SQUARE WAVE") { // this is not a valid CSW format file - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(CswConverter).ToString() + "This is not a valid CSW format file"); } if (data[0x16] != 0x1a) { // invalid terminator code - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(CswConverter).ToString() + "This image reports as a CSW but has an invalid terminator code"); } @@ -182,12 +185,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum if (compressionType == 1) Array.Copy(data, _position, cswDataUncompressed, 0, cswDataUncompressed.Length); else - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(CswConverter).ToString() + "CSW Format unknown compression type"); } else { - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(CswConverter).ToString() + "CSW Format Version " + majorVer + "." + minorVer + " is not currently supported"); } diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs index 8f79645d50..4d92fd8e50 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs @@ -9,7 +9,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// Reponsible for PZX format serializaton /// Based on the information here: http://zxds.raxoft.cz/docs/pzx.txt /// - public class PzxConverter : MediaConverter + public sealed class PzxConverter : MediaConverter { /// /// The type of serializer @@ -27,6 +27,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public override bool IsWriter => false; + protected override Type SelfType + => typeof(PzxConverter); + /// /// Working list of generated tape data blocks /// @@ -96,7 +99,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum if (ident.ToUpper() != "PZXT") { // this is not a valid TZX format file - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(PzxConverter).ToString() + "This is not a valid PZX format file"); } diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapConverter.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapConverter.cs index cdc0546da9..7e3906788f 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapConverter.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapConverter.cs @@ -27,6 +27,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public override bool IsWriter => false; + protected override Type SelfType + => typeof(TapConverter); + private readonly DatacorderDevice _datacorder; public TapConverter(DatacorderDevice _tapeDevice) diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/TzxConverter.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/TzxConverter.cs index 08f266c10f..b3373509fb 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/TzxConverter.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/TzxConverter.cs @@ -8,7 +8,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// Reponsible for TZX format serializaton /// - public class TzxConverter : MediaConverter + public sealed class TzxConverter : MediaConverter { /// /// The type of serializer @@ -26,6 +26,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public override bool IsWriter => false; + protected override Type SelfType + => typeof(TzxConverter); + /// /// Working list of generated tape data blocks /// @@ -202,7 +205,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum if (ident != "ZXTape!" || eotm != 0x1A) { // this is not a valid TZX format file - throw new Exception(this.GetType() + + throw new Exception(typeof(TzxConverter) + "This is not a valid TZX format file"); } diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/WAV/WavConverter.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/WAV/WavConverter.cs index 32bb577359..aa6e13c2d2 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/WAV/WavConverter.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/WAV/WavConverter.cs @@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// Reponsible for WAV format conversion /// Based heavily on code from zxmak2: https://archive.codeplex.com/?p=zxmak2 /// - public class WavConverter : MediaConverter + public sealed class WavConverter : MediaConverter { /// /// The type of serializer @@ -28,6 +28,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public override bool IsWriter => false; + protected override Type SelfType + => typeof(WavConverter); + /// /// Position counter /// @@ -74,7 +77,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum if (ident.ToUpper() != "WAVE") { // this is not a valid TZX format file - throw new Exception(this.GetType().ToString() + + throw new Exception(typeof(WavConverter).ToString() + "This is not a valid WAV format file"); } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs index 90fbe18be0..2b0c3abe92 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs @@ -212,7 +212,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES } [StructLayout(LayoutKind.Sequential)] - public class SnesCallbacks + public sealed class SnesCallbacks { public snes_video_frame_t videoFrameCb; public snes_audio_sample_t audioSampleCb; @@ -233,7 +233,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES public IEnumerable AllDelegatesInMemoryOrder() { - FieldsInOrder ??= GetType() + FieldsInOrder ??= typeof(SnesCallbacks) .GetFields() .OrderBy(BizInvokerUtilities.ComputeFieldOffset) .ToList(); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs index 8c392abfa4..bb8c880487 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs @@ -15,8 +15,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES { [PortedCore(CoreNames.QuickNes, "", "0.7.0", "https://github.com/kode54/QuickNES")] [ServiceNotApplicable(new[] { typeof(IDriveLight) })] - public partial class QuickNES : IEmulator, IVideoProvider, ISoundProvider, ISaveRam, IInputPollable, IBoardInfo, IVideoLogicalOffsets, - IStatable, IDebuggable, ISettable, INESPPUViewable + public sealed partial class QuickNES : IEmulator, IVideoProvider, ISoundProvider, ISaveRam, IInputPollable, + IBoardInfo, IVideoLogicalOffsets, IStatable, IDebuggable, + ISettable, INESPPUViewable { static QuickNES() { @@ -292,7 +293,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES private void CheckDisposed() { if (Context == IntPtr.Zero) - throw new ObjectDisposedException(GetType().Name); + throw new ObjectDisposedException(typeof(QuickNES).Name); } // Fix some incorrect ines header entries that QuickNES uses to load games. diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GenDbgHlp.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GenDbgHlp.cs index cd553a2d42..6a326a70a0 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GenDbgHlp.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GenDbgHlp.cs @@ -23,7 +23,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx * 3) support an ignore list of symbols */ - public class GenDbgHlp : IDisposable + public sealed class GenDbgHlp : IDisposable { // config private const string modulename = "libgenplusgx.dll"; @@ -49,7 +49,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx public void SaveState(int statenum) { - if (disposed) throw new ObjectDisposedException(this.GetType().ToString()); + if (disposed) throw new ObjectDisposedException(typeof(GenDbgHlp).ToString()); data[statenum] ??= new byte[length]; @@ -60,7 +60,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx public unsafe void Cmp(int statex, int statey) { - if (disposed) throw new ObjectDisposedException(this.GetType().ToString()); + if (disposed) throw new ObjectDisposedException(typeof(GenDbgHlp).ToString()); List> bads = new List>(); byte[] x = data[statex]; @@ -134,7 +134,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx public List Find(IntPtr addr, int length) { - if (disposed) throw new ObjectDisposedException(this.GetType().ToString()); + if (disposed) throw new ObjectDisposedException(typeof(GenDbgHlp).ToString()); Symbol min = new Symbol { addr = addr }; Symbol max = new Symbol { addr = addr + length };