From f3f90a4cd5dfd1bc351eb4771e1fe6fdd3f12d67 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 19 Jul 2022 03:45:38 +1000 Subject: [PATCH] Add Analyzer rules to prohibit `this.GetType()` seriously Meziantou is a godsend --- Common.ruleset | 6 +++ .../BizHawk.Analyzer/RoslynUtils.cs | 10 +++- .../UseTypeofOperatorAnalyzer.cs | 50 ++++++++++++++++++ References/BizHawk.Analyzer.dll | Bin 18432 -> 20992 bytes .../Hardware/Datacorder/DatacorderDevice.cs | 4 +- .../AmstradCPC/Hardware/Disk/NECUPD765.FDD.cs | 4 +- .../AmstradCPC/Machine/CPCBase.Media.cs | 2 +- .../AmstradCPC/Media/MediaConverter.cs | 8 +-- .../AmstradCPC/Media/Tape/CDT/CdtConverter.cs | 7 ++- .../Hardware/Datacorder/DatacorderDevice.cs | 12 ++--- .../Hardware/Disk/NECUPD765.FDD.cs | 4 +- .../Machine/SpectrumBase.Media.cs | 2 +- .../Machine/SpectrumBase.Memory.cs | 11 +--- .../SinclairSpectrum/Media/MediaConverter.cs | 8 +-- .../Media/Tape/CSW/CswConverter.cs | 13 +++-- .../Media/Tape/PZX/PzxConverter.cs | 7 ++- .../Media/Tape/TAP/TapConverter.cs | 3 ++ .../Media/Tape/TZX/TzxConverter.cs | 7 ++- .../Media/Tape/WAV/WavConverter.cs | 7 ++- .../Consoles/Nintendo/BSNES/BsnesApi.cs | 4 +- .../Consoles/Nintendo/QuickNES/QuickNES.cs | 7 +-- .../Consoles/Sega/gpgx64/GenDbgHlp.cs | 8 +-- 22 files changed, 131 insertions(+), 53 deletions(-) create mode 100644 ExternalProjects/BizHawk.Analyzer/UseTypeofOperatorAnalyzer.cs 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 4fe37a090993acbe0e3c0d2e85570e172f23679b..cfa7f15ff033e5a547ba1c44c0e604b2f06e4650 100644 GIT binary patch literal 20992 zcmeHv3wT`Bb?!Q6X3oqUNh8h3@(bIH{D84+$&%$a*s-2iU`e(mV;mmxcyugJJeniV z!?rLo<2daX2)=)1)LV+<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HA0;kzRllGb>ZDN{?5NFAJ#uk>4uN*cP z7zI|6{Moaa(gXDGbd@gQJ~LL4mrflgo}W})GBpa}8kz@51ix+^{`K>KzXb=ahc}xW zL6A=$~ubvJ&|>QWa4xvay!m`{M{(~(@fI$DlPnt!Fiv3 zn(>WOygU1ihWKHGCm%Hz;4Q>kgpnA9!Y1PP;S{u!QYP$ zmCYP{r)-hxPA;!@zgB*%aK)}I+go=o-MD2PZCSs)b9?KSb*s-Mf2wIuV{mlZn{aw)t?f1y|aRi3l}_7c;`9gub&FK z-?=#{F1lxLo|Dd8QbM6IA3Zfp9h&*>a2^H5M)Z#^mWG)pr>(S4L3Y@-XIR>SJ ze>*?m^R=kDv)p}rVSL$2_y`}06k~k2CCN@Z%OvZpl9vWQDd;12`OFCVnGy6qU?@GK zL+!jCbzAD);u7+L;-I8bN&F9dN4S^xk5 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 };