Enable MA0098 and fix noncompliance
"Use indexer instead of LINQ methods"
This commit is contained in:
parent
ee11385f10
commit
17df5673d2
|
@ -402,7 +402,7 @@
|
|||
<Rule Id="MA0097" Action="Hidden" />
|
||||
|
||||
<!-- Use indexer instead of LINQ methods -->
|
||||
<Rule Id="MA0098" Action="Hidden" />
|
||||
<Rule Id="MA0098" Action="Warning" />
|
||||
|
||||
<!-- Use Explicit enum value instead of 0 -->
|
||||
<Rule Id="MA0099" Action="Hidden" />
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Common.StringExtensions;
|
||||
|
||||
|
@ -79,18 +78,8 @@ namespace BizHawk.Common.PathExtensions
|
|||
//TODO merge this with the Windows implementation in MakeRelativeTo
|
||||
static FileAttributes GetPathAttribute(string path1)
|
||||
{
|
||||
var di = new DirectoryInfo(path1.Split('|').First());
|
||||
if (di.Exists)
|
||||
{
|
||||
return FileAttributes.Directory;
|
||||
}
|
||||
|
||||
var fi = new FileInfo(path1.Split('|').First());
|
||||
if (fi.Exists)
|
||||
{
|
||||
return FileAttributes.Normal;
|
||||
}
|
||||
|
||||
if (Directory.Exists(path1.SubstringBefore('|'))) return FileAttributes.Directory;
|
||||
if (File.Exists(path1.SubstringBefore('|'))) return FileAttributes.Normal;
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// the substring of <paramref name="str"/> before the first occurrence of <paramref name="delimiter"/>, or
|
||||
/// the original <paramref name="str"/> if not found
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BizHawk.Emulation.Common
|
||||
{
|
||||
|
@ -58,7 +57,7 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
public MemoryDomain MainMemory
|
||||
{
|
||||
get => _mainMemory ?? this.First();
|
||||
get => _mainMemory ?? this[0];
|
||||
set => _mainMemory = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Arcades.MAME
|
||||
|
@ -31,10 +32,8 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
|
|||
{
|
||||
if (portField != string.Empty)
|
||||
{
|
||||
string[] substrings = portField.Split(',');
|
||||
string tag = substrings.First();
|
||||
string field = substrings.Last();
|
||||
|
||||
var tag = portField.SubstringBefore(',');
|
||||
var field = portField.SubstringAfterLast(',');
|
||||
_fieldsPorts.Add(field, tag);
|
||||
MAMEController.BoolButtons.Add(field);
|
||||
}
|
||||
|
|
|
@ -1007,18 +1007,8 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
var padPos = pad * -1;
|
||||
var excessL = padPos / 2;
|
||||
var excessR = excessL + (padPos % 2);
|
||||
for (int i = 0; i < excessL; i++)
|
||||
{
|
||||
var lThing = lCop.First();
|
||||
|
||||
lCop.Remove(lThing);
|
||||
}
|
||||
for (int i = 0; i < excessL; i++)
|
||||
{
|
||||
var lThing = lCop.Last();
|
||||
|
||||
lCop.Remove(lThing);
|
||||
}
|
||||
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 lPad = pad / 2;
|
||||
|
|
|
@ -662,7 +662,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
for (int i = 0; i < size - ActualDataByteLength; i++)
|
||||
{
|
||||
//l.Add(SectorData[i]);
|
||||
l.Add(SectorData.Last());
|
||||
l.Add(SectorData[SectorData.Length - 1]);
|
||||
}
|
||||
|
||||
return l.ToArray();
|
||||
|
|
|
@ -367,7 +367,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
_position += blockLen;
|
||||
|
||||
// generate PAUSE block
|
||||
CreatePauseBlock(_datacorder.DataBlocks.Last());
|
||||
CreatePauseBlock(_datacorder.DataBlocks[_datacorder.DataBlocks.Count - 1]);
|
||||
}
|
||||
|
||||
/* length: [0F,10,11]+12
|
||||
|
@ -427,7 +427,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
_position += blockLen;
|
||||
|
||||
// generate PAUSE block
|
||||
CreatePauseBlock(_datacorder.DataBlocks.Last());
|
||||
CreatePauseBlock(_datacorder.DataBlocks[_datacorder.DataBlocks.Count - 1]);
|
||||
}
|
||||
|
||||
/* length: 04
|
||||
|
@ -551,7 +551,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
_position += blockLen;
|
||||
|
||||
// generate PAUSE block
|
||||
CreatePauseBlock(_datacorder.DataBlocks.Last());
|
||||
CreatePauseBlock(_datacorder.DataBlocks[_datacorder.DataBlocks.Count - 1]);
|
||||
}
|
||||
|
||||
/* length: [05,06,07]+08
|
||||
|
@ -657,7 +657,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
_datacorder.DataBlocks.Add(t);
|
||||
|
||||
// generate PAUSE block
|
||||
CreatePauseBlock(_datacorder.DataBlocks.Last());
|
||||
CreatePauseBlock(_datacorder.DataBlocks[_datacorder.DataBlocks.Count - 1]);
|
||||
}
|
||||
|
||||
/* length: [00,01,02,03]+04
|
||||
|
@ -728,7 +728,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
_datacorder.DataBlocks.Add(t);
|
||||
|
||||
// generate PAUSE block
|
||||
CreatePauseBlock(_datacorder.DataBlocks.Last());
|
||||
CreatePauseBlock(_datacorder.DataBlocks[_datacorder.DataBlocks.Count - 1]);
|
||||
}
|
||||
|
||||
/* length: [00,01,02,03]+04
|
||||
|
@ -880,7 +880,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
_position += 2;
|
||||
|
||||
// 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)
|
||||
{
|
||||
// Force certain drive types to be available depending on ROM type
|
||||
var rom = _roms.First();
|
||||
var rom = _roms[0];
|
||||
|
||||
switch (C64FormatFinder.GetFormat(rom))
|
||||
{
|
||||
|
|
|
@ -665,7 +665,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
for (int i = 0; i < size - ActualDataByteLength; i++)
|
||||
{
|
||||
//l.Add(SectorData[i]);
|
||||
l.Add(SectorData.Last());
|
||||
l.Add(SectorData[SectorData.Length - 1]);
|
||||
}
|
||||
|
||||
return l.ToArray();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
||||
|
@ -81,7 +81,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
{
|
||||
Name = _game.Name,
|
||||
System = VSystemID.Raw.A26,
|
||||
MetaData = "m=" + _mapper.GetType().ToString().Split('.').Last(),
|
||||
MetaData = "m=" + _mapper.GetType().ToString().SubstringAfterLast('.'),
|
||||
Hash = SHA1Checksum.ComputeDigestHex(Rom),
|
||||
Region = _game.Region,
|
||||
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_sl90025"));
|
||||
|
||||
Cartridge = VesCartBase.Configure(_gameInfo.First(), _files.First());
|
||||
Cartridge = VesCartBase.Configure(_gameInfo[0], _files[0]);
|
||||
|
||||
BIOS01 = bios01;
|
||||
BIOS02 = bios02;
|
||||
|
|
|
@ -67,6 +67,15 @@ namespace BizHawk.Tests.Common.StringExtensions
|
|||
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]
|
||||
public void TestSubstringBefore()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue