Enable MA0098 and fix noncompliance
"Use indexer instead of LINQ methods"
This commit is contained in:
parent
ee11385f10
commit
17df5673d2
Common.ruleset
src
BizHawk.Common/Extensions
BizHawk.Emulation.Common/Base Implementations
BizHawk.Emulation.Cores
Arcades/MAME
Computers
AmstradCPC
Commodore64
SinclairSpectrum/Media/Disk
Consoles
BizHawk.Tests/Common/StringExtensions
|
@ -402,7 +402,7 @@
|
||||||
<Rule Id="MA0097" Action="Hidden" />
|
<Rule Id="MA0097" Action="Hidden" />
|
||||||
|
|
||||||
<!-- Use indexer instead of LINQ methods -->
|
<!-- Use indexer instead of LINQ methods -->
|
||||||
<Rule Id="MA0098" Action="Hidden" />
|
<Rule Id="MA0098" Action="Warning" />
|
||||||
|
|
||||||
<!-- Use Explicit enum value instead of 0 -->
|
<!-- Use Explicit enum value instead of 0 -->
|
||||||
<Rule Id="MA0099" Action="Hidden" />
|
<Rule Id="MA0099" Action="Hidden" />
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
using BizHawk.Common.StringExtensions;
|
using BizHawk.Common.StringExtensions;
|
||||||
|
|
||||||
|
@ -79,18 +78,8 @@ namespace BizHawk.Common.PathExtensions
|
||||||
//TODO merge this with the Windows implementation in MakeRelativeTo
|
//TODO merge this with the Windows implementation in MakeRelativeTo
|
||||||
static FileAttributes GetPathAttribute(string path1)
|
static FileAttributes GetPathAttribute(string path1)
|
||||||
{
|
{
|
||||||
var di = new DirectoryInfo(path1.Split('|').First());
|
if (Directory.Exists(path1.SubstringBefore('|'))) return FileAttributes.Directory;
|
||||||
if (di.Exists)
|
if (File.Exists(path1.SubstringBefore('|'))) return FileAttributes.Normal;
|
||||||
{
|
|
||||||
return FileAttributes.Directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
var fi = new FileInfo(path1.Split('|').First());
|
|
||||||
if (fi.Exists)
|
|
||||||
{
|
|
||||||
return FileAttributes.Normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new FileNotFoundException();
|
throw new FileNotFoundException();
|
||||||
}
|
}
|
||||||
var path = new StringBuilder(260 /* = MAX_PATH */);
|
var path = new StringBuilder(260 /* = MAX_PATH */);
|
||||||
|
|
|
@ -82,6 +82,23 @@ namespace BizHawk.Common.StringExtensions
|
||||||
return index < 0 ? notFoundValue : str.Substring(index + delimiter.Length, str.Length - index - delimiter.Length);
|
return index < 0 ? notFoundValue : str.Substring(index + delimiter.Length, str.Length - index - delimiter.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <returns>
|
||||||
|
/// the substring of <paramref name="str"/> after the last occurrence of <paramref name="delimiter"/>, or
|
||||||
|
/// the original <paramref name="str"/> if not found
|
||||||
|
/// </returns>
|
||||||
|
public static string SubstringAfterLast(this string str, char delimiter)
|
||||||
|
=> str.SubstringAfterLast(delimiter, notFoundValue: str);
|
||||||
|
|
||||||
|
/// <returns>
|
||||||
|
/// the substring of <paramref name="str"/> after the last occurrence of <paramref name="delimiter"/>, or
|
||||||
|
/// <paramref name="notFoundValue"/> if not found
|
||||||
|
/// </returns>
|
||||||
|
public static string SubstringAfterLast(this string str, char delimiter, string notFoundValue)
|
||||||
|
{
|
||||||
|
var index = str.LastIndexOf(delimiter);
|
||||||
|
return index < 0 ? notFoundValue : str.Substring(index + 1, str.Length - index - 1);
|
||||||
|
}
|
||||||
|
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// the substring of <paramref name="str"/> before the first occurrence of <paramref name="delimiter"/>, or
|
/// the substring of <paramref name="str"/> before the first occurrence of <paramref name="delimiter"/>, or
|
||||||
/// the original <paramref name="str"/> if not found
|
/// the original <paramref name="str"/> if not found
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Common
|
namespace BizHawk.Emulation.Common
|
||||||
{
|
{
|
||||||
|
@ -58,7 +57,7 @@ namespace BizHawk.Emulation.Common
|
||||||
|
|
||||||
if (_sink != null)
|
if (_sink != null)
|
||||||
{
|
{
|
||||||
var scope = DebuggableCore.MemoryCallbacks.AvailableScopes.First(); // This will be an issue when cores use this trace buffer and utilize multiple scopes
|
var scope = DebuggableCore.MemoryCallbacks.AvailableScopes[0]; // This will be an issue when cores use this trace buffer and utilize multiple scopes
|
||||||
DebuggableCore.MemoryCallbacks.Add(new TracingMemoryCallback(TraceFromCallback, scope));
|
DebuggableCore.MemoryCallbacks.Add(new TracingMemoryCallback(TraceFromCallback, scope));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Common
|
||||||
|
|
||||||
public MemoryDomain MainMemory
|
public MemoryDomain MainMemory
|
||||||
{
|
{
|
||||||
get => _mainMemory ?? this.First();
|
get => _mainMemory ?? this[0];
|
||||||
set => _mainMemory = value;
|
set => _mainMemory = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
|
using BizHawk.Common.StringExtensions;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Cores.Arcades.MAME
|
namespace BizHawk.Emulation.Cores.Arcades.MAME
|
||||||
|
@ -31,10 +32,8 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
|
||||||
{
|
{
|
||||||
if (portField != string.Empty)
|
if (portField != string.Empty)
|
||||||
{
|
{
|
||||||
string[] substrings = portField.Split(',');
|
var tag = portField.SubstringBefore(',');
|
||||||
string tag = substrings.First();
|
var field = portField.SubstringAfterLast(',');
|
||||||
string field = substrings.Last();
|
|
||||||
|
|
||||||
_fieldsPorts.Add(field, tag);
|
_fieldsPorts.Add(field, tag);
|
||||||
MAMEController.BoolButtons.Add(field);
|
MAMEController.BoolButtons.Add(field);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1007,18 +1007,8 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
||||||
var padPos = pad * -1;
|
var padPos = pad * -1;
|
||||||
var excessL = padPos / 2;
|
var excessL = padPos / 2;
|
||||||
var excessR = excessL + (padPos % 2);
|
var excessR = excessL + (padPos % 2);
|
||||||
for (int i = 0; i < excessL; i++)
|
for (var i = 0; i < excessL; i++) lCop.RemoveAt(0);
|
||||||
{
|
for (var i = 0; i < excessL; i++) lCop.RemoveAt(lCop.Count - 1); //TODO should be using excessR?
|
||||||
var lThing = lCop.First();
|
|
||||||
|
|
||||||
lCop.Remove(lThing);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < excessL; i++)
|
|
||||||
{
|
|
||||||
var lThing = lCop.Last();
|
|
||||||
|
|
||||||
lCop.Remove(lThing);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var lPad = pad / 2;
|
var lPad = pad / 2;
|
||||||
|
|
|
@ -662,7 +662,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
||||||
for (int i = 0; i < size - ActualDataByteLength; i++)
|
for (int i = 0; i < size - ActualDataByteLength; i++)
|
||||||
{
|
{
|
||||||
//l.Add(SectorData[i]);
|
//l.Add(SectorData[i]);
|
||||||
l.Add(SectorData.Last());
|
l.Add(SectorData[SectorData.Length - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return l.ToArray();
|
return l.ToArray();
|
||||||
|
|
|
@ -367,7 +367,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
||||||
_position += blockLen;
|
_position += blockLen;
|
||||||
|
|
||||||
// generate PAUSE block
|
// generate PAUSE block
|
||||||
CreatePauseBlock(_datacorder.DataBlocks.Last());
|
CreatePauseBlock(_datacorder.DataBlocks[_datacorder.DataBlocks.Count - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* length: [0F,10,11]+12
|
/* length: [0F,10,11]+12
|
||||||
|
@ -427,7 +427,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
||||||
_position += blockLen;
|
_position += blockLen;
|
||||||
|
|
||||||
// generate PAUSE block
|
// generate PAUSE block
|
||||||
CreatePauseBlock(_datacorder.DataBlocks.Last());
|
CreatePauseBlock(_datacorder.DataBlocks[_datacorder.DataBlocks.Count - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* length: 04
|
/* length: 04
|
||||||
|
@ -551,7 +551,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
||||||
_position += blockLen;
|
_position += blockLen;
|
||||||
|
|
||||||
// generate PAUSE block
|
// generate PAUSE block
|
||||||
CreatePauseBlock(_datacorder.DataBlocks.Last());
|
CreatePauseBlock(_datacorder.DataBlocks[_datacorder.DataBlocks.Count - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* length: [05,06,07]+08
|
/* length: [05,06,07]+08
|
||||||
|
@ -657,7 +657,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
||||||
_datacorder.DataBlocks.Add(t);
|
_datacorder.DataBlocks.Add(t);
|
||||||
|
|
||||||
// generate PAUSE block
|
// generate PAUSE block
|
||||||
CreatePauseBlock(_datacorder.DataBlocks.Last());
|
CreatePauseBlock(_datacorder.DataBlocks[_datacorder.DataBlocks.Count - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* length: [00,01,02,03]+04
|
/* length: [00,01,02,03]+04
|
||||||
|
@ -728,7 +728,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
||||||
_datacorder.DataBlocks.Add(t);
|
_datacorder.DataBlocks.Add(t);
|
||||||
|
|
||||||
// generate PAUSE block
|
// generate PAUSE block
|
||||||
CreatePauseBlock(_datacorder.DataBlocks.Last());
|
CreatePauseBlock(_datacorder.DataBlocks[_datacorder.DataBlocks.Count - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* length: [00,01,02,03]+04
|
/* length: [00,01,02,03]+04
|
||||||
|
@ -880,7 +880,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
||||||
_position += 2;
|
_position += 2;
|
||||||
|
|
||||||
// generate PAUSE block
|
// generate PAUSE block
|
||||||
CreatePauseBlock(_datacorder.DataBlocks.Last());
|
CreatePauseBlock(_datacorder.DataBlocks[_datacorder.DataBlocks.Count - 1]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,7 +252,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
|
||||||
private void Init(VicType initRegion, BorderType borderType, SidType sidType, TapeDriveType tapeDriveType, DiskDriveType diskDriveType)
|
private void Init(VicType initRegion, BorderType borderType, SidType sidType, TapeDriveType tapeDriveType, DiskDriveType diskDriveType)
|
||||||
{
|
{
|
||||||
// Force certain drive types to be available depending on ROM type
|
// Force certain drive types to be available depending on ROM type
|
||||||
var rom = _roms.First();
|
var rom = _roms[0];
|
||||||
|
|
||||||
switch (C64FormatFinder.GetFormat(rom))
|
switch (C64FormatFinder.GetFormat(rom))
|
||||||
{
|
{
|
||||||
|
|
|
@ -665,7 +665,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
||||||
for (int i = 0; i < size - ActualDataByteLength; i++)
|
for (int i = 0; i < size - ActualDataByteLength; i++)
|
||||||
{
|
{
|
||||||
//l.Add(SectorData[i]);
|
//l.Add(SectorData[i]);
|
||||||
l.Add(SectorData.Last());
|
l.Add(SectorData[SectorData.Length - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return l.ToArray();
|
return l.ToArray();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
|
using BizHawk.Common.StringExtensions;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
||||||
|
@ -81,7 +81,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
||||||
{
|
{
|
||||||
Name = _game.Name,
|
Name = _game.Name,
|
||||||
System = VSystemID.Raw.A26,
|
System = VSystemID.Raw.A26,
|
||||||
MetaData = "m=" + _mapper.GetType().ToString().Split('.').Last(),
|
MetaData = "m=" + _mapper.GetType().ToString().SubstringAfterLast('.'),
|
||||||
Hash = SHA1Checksum.ComputeDigestHex(Rom),
|
Hash = SHA1Checksum.ComputeDigestHex(Rom),
|
||||||
Region = _game.Region,
|
Region = _game.Region,
|
||||||
Status = RomStatus.Unknown
|
Status = RomStatus.Unknown
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF
|
||||||
var bios02 = CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("ChannelF", "ChannelF_sl131254"));
|
var bios02 = CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("ChannelF", "ChannelF_sl131254"));
|
||||||
//var bios02 = CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("ChannelF", "ChannelF_sl90025"));
|
//var bios02 = CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("ChannelF", "ChannelF_sl90025"));
|
||||||
|
|
||||||
Cartridge = VesCartBase.Configure(_gameInfo.First(), _files.First());
|
Cartridge = VesCartBase.Configure(_gameInfo[0], _files[0]);
|
||||||
|
|
||||||
BIOS01 = bios01;
|
BIOS01 = bios01;
|
||||||
BIOS02 = bios02;
|
BIOS02 = bios02;
|
||||||
|
|
|
@ -67,6 +67,15 @@ namespace BizHawk.Tests.Common.StringExtensions
|
||||||
Assert.AreEqual(qrs, string.Empty.SubstringAfter("abc", qrs));
|
Assert.AreEqual(qrs, string.Empty.SubstringAfter("abc", qrs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestSubstringAfterLast()
|
||||||
|
{
|
||||||
|
// fewer tests for SubstringAfterLast as its implementation should match SubstringAfter, save for using LastIndexOf
|
||||||
|
|
||||||
|
Assert.AreEqual("ab", "abcdabcdab".SubstringAfterLast('d', qrs));
|
||||||
|
Assert.AreEqual(qrs, "abcdabcdab".SubstringAfterLast('x', qrs));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestSubstringBefore()
|
public void TestSubstringBefore()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue