Enable MA0020 and fix noncompliance
"Use direct methods instead of LINQ methods"
This commit is contained in:
parent
697c10e3e6
commit
26b6a1c4a9
|
@ -171,7 +171,7 @@
|
|||
<Rule Id="MA0019" Action="Error" />
|
||||
|
||||
<!-- Use direct methods instead of LINQ methods -->
|
||||
<Rule Id="MA0020" Action="Hidden" />
|
||||
<Rule Id="MA0020" Action="Error" />
|
||||
|
||||
<!-- Use StringComparer.GetHashCode instead of string.GetHashCode -->
|
||||
<Rule Id="MA0021" Action="Hidden" />
|
||||
|
|
|
@ -120,9 +120,8 @@ namespace BizHawk.Client.Common
|
|||
public IEnumerator<PathEntry> GetEnumerator() => Paths.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
public PathEntry this[string system, string type] =>
|
||||
Paths.FirstOrDefault(p => p.IsSystem(system) && p.Type == type)
|
||||
?? TryGetDebugPath(system, type);
|
||||
public PathEntry this[string system, string type]
|
||||
=> Paths.Find(p => p.IsSystem(system) && p.Type == type) ?? TryGetDebugPath(system, type);
|
||||
|
||||
private PathEntry TryGetDebugPath(string system, string type)
|
||||
{
|
||||
|
@ -143,11 +142,7 @@ namespace BizHawk.Client.Common
|
|||
// Add missing entries
|
||||
foreach (var defaultPath in Defaults.Value)
|
||||
{
|
||||
var path = Paths.FirstOrDefault(p => p.System == defaultPath.System && p.Type == defaultPath.Type);
|
||||
if (path == null)
|
||||
{
|
||||
Paths.Add(defaultPath);
|
||||
}
|
||||
if (!Paths.Any(p => p.System == defaultPath.System && p.Type == defaultPath.Type)) Paths.Add(defaultPath);
|
||||
}
|
||||
|
||||
var entriesToRemove = new List<PathEntry>();
|
||||
|
|
|
@ -15,8 +15,8 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public LuaFunctionList(Action onChanged) => Changed = onChanged;
|
||||
|
||||
public NamedLuaFunction this[string guid] =>
|
||||
_functions.FirstOrDefault(nlf => nlf.Guid.ToString() == guid);
|
||||
public NamedLuaFunction this[string guid]
|
||||
=> _functions.Find(nlf => nlf.Guid.ToString() == guid);
|
||||
|
||||
public void Add(NamedLuaFunction nlf)
|
||||
{
|
||||
|
|
|
@ -68,9 +68,8 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public Cheat this[int index] => _cheatList[index];
|
||||
|
||||
public Cheat this[MemoryDomain domain, long address] =>
|
||||
_cheatList.FirstOrDefault(cheat => cheat.Domain == domain && cheat.Address == address);
|
||||
|
||||
public Cheat this[MemoryDomain domain, long address]
|
||||
=> _cheatList.Find(cheat => cheat.Domain == domain && cheat.Address == address);
|
||||
|
||||
public IEnumerator<Cheat> GetEnumerator() => _cheatList.GetEnumerator();
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
|
@ -28,14 +27,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
_capacity = capacity;
|
||||
}
|
||||
|
||||
private T[] GetBufferInternal(int length, bool zerofill, Func<T[], bool> criteria)
|
||||
private T[] GetBufferInternal(int length, bool zerofill, Predicate<T[]> criteria)
|
||||
{
|
||||
if (_inUse.Count == _capacity)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
T[] candidate = _available.FirstOrDefault(criteria);
|
||||
var candidate = _available.Find(criteria);
|
||||
if (candidate == null)
|
||||
{
|
||||
if (_available.Count + _inUse.Count == _capacity)
|
||||
|
|
|
@ -171,9 +171,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
private bool IsDuplicate(string binding)
|
||||
{
|
||||
return _bindings.FirstOrDefault(x => x == binding) != null;
|
||||
}
|
||||
=> _bindings.Contains(binding);
|
||||
|
||||
protected override void OnKeyUp(KeyEventArgs e)
|
||||
{
|
||||
|
|
|
@ -53,15 +53,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
var selectedSystemId = _preferredPlatformsForExtensions[FileExtension];
|
||||
if (!string.IsNullOrEmpty(selectedSystemId))
|
||||
{
|
||||
var selectedSystem = _availableSystems.FirstOrDefault(s => s.SystemId == selectedSystemId);
|
||||
|
||||
var selectedItem = PlatformDropdown.Items
|
||||
.OfType<string>()
|
||||
.FirstOrDefault(item => item == (selectedSystem?.FullName ?? ""));
|
||||
|
||||
if (selectedItem != null)
|
||||
var selectedSystem = _availableSystems.Find(s => s.SystemId == selectedSystemId)?.FullName ?? string.Empty;
|
||||
if (PlatformDropdown.Items.Contains(selectedSystem))
|
||||
{
|
||||
PlatformDropdown.SelectedItem = selectedItem;
|
||||
PlatformDropdown.SelectedItem = selectedSystem;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -25,14 +25,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void WindowClosed(IntPtr handle)
|
||||
{
|
||||
var form = _luaForms.FirstOrDefault(form => form.Handle == handle);
|
||||
if (form != null) _luaForms.Remove(form);
|
||||
var i = _luaForms.FindIndex(form => form.Handle == handle);
|
||||
if (i is not -1) _luaForms.RemoveAt(i);
|
||||
}
|
||||
|
||||
private LuaWinform GetForm(int formHandle)
|
||||
{
|
||||
var ptr = new IntPtr(formHandle);
|
||||
return _luaForms.FirstOrDefault(form => form.Handle == ptr);
|
||||
return _luaForms.Find(form => form.Handle == ptr);
|
||||
}
|
||||
|
||||
private static void SetLocation(Control control, int x, int y)
|
||||
|
|
|
@ -455,21 +455,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// </summary>
|
||||
/// <typeparam name="T">Type of tool to check</typeparam>
|
||||
public bool IsLoaded<T>() where T : IToolForm
|
||||
{
|
||||
var existingTool = _tools.FirstOrDefault(t => t is T);
|
||||
if (existingTool != null)
|
||||
{
|
||||
return existingTool.IsActive;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
=> _tools.OfType<T>().FirstOrDefault()?.IsActive is true;
|
||||
|
||||
public bool IsLoaded(Type toolType)
|
||||
{
|
||||
var existingTool = _tools.FirstOrDefault(t => t.GetType() == toolType);
|
||||
return existingTool != null && existingTool.IsActive;
|
||||
}
|
||||
=> _tools.Find(t => t.GetType() == toolType)?.IsActive is true;
|
||||
|
||||
public bool IsOnScreen(Point topLeft)
|
||||
{
|
||||
|
@ -511,8 +500,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// <typeparam name="T">Type of tool to update</typeparam>
|
||||
public void UpdateValues<T>() where T : IToolForm
|
||||
{
|
||||
var tool = _tools.FirstOrDefault(t => t is T);
|
||||
if (tool != null && tool.IsActive)
|
||||
var tool = _tools.OfType<T>().FirstOrDefault();
|
||||
if (tool?.IsActive is true)
|
||||
{
|
||||
tool.UpdateValues(ToolFormUpdateType.General);
|
||||
}
|
||||
|
@ -568,10 +557,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// </summary>
|
||||
/// <typeparam name="T">Type of tool to restart</typeparam>
|
||||
public void Restart<T>() where T : IToolForm
|
||||
{
|
||||
var tool = _tools.FirstOrDefault(t => t is T);
|
||||
tool?.Restart();
|
||||
}
|
||||
=> _tools.OfType<T>().FirstOrDefault()?.Restart();
|
||||
|
||||
/// <summary>
|
||||
/// Runs AskSave on every tool dialog, false is returned if any tool returns false
|
||||
|
@ -594,7 +580,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// <typeparam name="T">Type of tool to close</typeparam>
|
||||
public void Close<T>() where T : IToolForm
|
||||
{
|
||||
var tool = _tools.FirstOrDefault(t => t is T);
|
||||
var tool = _tools.OfType<T>().FirstOrDefault();
|
||||
if (tool != null)
|
||||
{
|
||||
tool.Close();
|
||||
|
@ -604,8 +590,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void Close(Type toolType)
|
||||
{
|
||||
var tool = _tools.FirstOrDefault(toolType.IsInstanceOfType);
|
||||
|
||||
var tool = _tools.Find(toolType.IsInstanceOfType);
|
||||
if (tool != null)
|
||||
{
|
||||
tool.Close();
|
||||
|
|
|
@ -346,8 +346,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
.OrderBy(x => x.TabIndex)
|
||||
.ToList();
|
||||
|
||||
var selected = radios.FirstOrDefault(x => x.Checked);
|
||||
var index = radios.IndexOf(selected);
|
||||
var index = radios.FindIndex(static x => x.Checked);
|
||||
|
||||
if (reverse)
|
||||
{
|
||||
|
@ -382,8 +381,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
.OrderBy(x => x.TabIndex)
|
||||
.ToList();
|
||||
|
||||
var selected = radios.FirstOrDefault(x => x.Checked);
|
||||
var index = radios.IndexOf(selected);
|
||||
var index = radios.FindIndex(static x => x.Checked);
|
||||
|
||||
if (reverse)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BizHawk.Emulation.Common
|
||||
{
|
||||
|
@ -38,8 +37,7 @@ namespace BizHawk.Emulation.Common
|
|||
};
|
||||
|
||||
public SystemInfo this[string systemId]
|
||||
=> _systems.FirstOrDefault(s => s.SystemId == systemId)
|
||||
?? new SystemInfo("Unknown", "Unknown");
|
||||
=> _systems.Find(s => s.SystemId == systemId) ?? new("Unknown", "Unknown");
|
||||
|
||||
public IEnumerable<SystemInfo> AllSystems => _systems;
|
||||
|
||||
|
|
|
@ -2493,9 +2493,8 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
cmdByte = cByte;
|
||||
|
||||
// lookup the command
|
||||
var cmd = CommandList.FirstOrDefault(a => a.CommandCode == cmdByte);
|
||||
|
||||
if (cmd == null)
|
||||
var i = CommandList.FindIndex(a => a.CommandCode == cmdByte);
|
||||
if (i is -1)
|
||||
{
|
||||
// no command found - use invalid
|
||||
CMDIndex = CommandList.Count - 1;
|
||||
|
@ -2503,7 +2502,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
else
|
||||
{
|
||||
// valid command found
|
||||
CMDIndex = CommandList.FindIndex(a => a.CommandCode == cmdByte);
|
||||
CMDIndex = i;
|
||||
|
||||
// check validity of command byte flags
|
||||
// if a flag is set but not valid for this command then it is invalid
|
||||
|
|
|
@ -2517,9 +2517,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
cmdByte = cByte;
|
||||
|
||||
// lookup the command
|
||||
var cmd = CommandList.FirstOrDefault(a => a.CommandCode == cmdByte);
|
||||
|
||||
if (cmd == null)
|
||||
var i = CommandList.FindIndex(a => a.CommandCode == cmdByte);
|
||||
if (i is -1)
|
||||
{
|
||||
// no command found - use invalid
|
||||
CMDIndex = CommandList.Count - 1;
|
||||
|
@ -2527,7 +2526,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
else
|
||||
{
|
||||
// valid command found
|
||||
CMDIndex = CommandList.FindIndex(a => a.CommandCode == cmdByte);
|
||||
CMDIndex = i;
|
||||
|
||||
// check validity of command byte flags
|
||||
// if a flag is set but not valid for this command then it is invalid
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
}
|
||||
|
||||
// now process the blocks
|
||||
var infoBlock = blocks.FirstOrDefault(a => a.RecordType == RecordHeaderType.INFO);
|
||||
var infoBlock = blocks.Find(static a => a.RecordType == RecordHeaderType.INFO);
|
||||
var IMGEblocks = blocks.Where(a => a.RecordType == RecordHeaderType.IMGE).ToList();
|
||||
var DATAblocks = blocks.Where(a => a.RecordType == RecordHeaderType.DATA);
|
||||
|
||||
|
|
|
@ -72,13 +72,12 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
|
||||
var devices = portInfo.Devices;
|
||||
|
||||
var device = devices.FirstOrDefault(a => a.ShortName == deviceName);
|
||||
var device = devices.Find(a => a.ShortName == deviceName);
|
||||
if (device == null)
|
||||
{
|
||||
Console.WriteLine($"Warn: unknown controller device {deviceName}");
|
||||
device = devices.FirstOrDefault(a => a.ShortName == portInfo.DefaultDeviceShortName);
|
||||
if (device == null)
|
||||
throw new InvalidOperationException($"Fail: unknown controller device {portInfo.DefaultDeviceShortName}");
|
||||
device = devices.Find(a => a.ShortName == portInfo.DefaultDeviceShortName)
|
||||
?? throw new InvalidOperationException($"Fail: unknown controller device {portInfo.DefaultDeviceShortName}");
|
||||
}
|
||||
|
||||
ActualPortData.Add(new PortResult
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace BizHawk.Emulation.DiscSystem
|
|||
throw new Blob_WaveFile_Exception("Not a RIFF WAVE file");
|
||||
}
|
||||
|
||||
if (!(rm.riff.subchunks.FirstOrDefault(chunk => chunk.tag == "fmt ") is RiffMaster.RiffSubchunk_fmt fmt))
|
||||
if (rm.riff.subchunks.Find(static chunk => chunk.tag == "fmt ") is not RiffMaster.RiffSubchunk_fmt fmt)
|
||||
{
|
||||
throw new Blob_WaveFile_Exception("Not a valid RIFF WAVE file (missing fmt chunk");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue