From cc0f1417f1fa64fa267896a45c55417f707428dc Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 31 Jan 2025 14:15:03 +1000 Subject: [PATCH] Enable a bunch of Analyzer rules re: `.Count()`/`.Any()` and fix cases --- .global.editorconfig.ini | 15 ++++++++++- .../DisplayManager/OSDManager.cs | 2 +- src/BizHawk.Client.Common/RecentFiles.cs | 10 ++++--- .../lua/LuaFunctionList.cs | 3 +++ .../movie/bk2/Bk2Movie.ModeApi.cs | 6 ++--- .../movie/import/IMovieImport.cs | 3 +-- .../movie/import/SmvImport.cs | 3 +-- .../movie/tasproj/TasMovie.Editing.cs | 2 +- .../movie/tasproj/TasMovie.IO.cs | 8 ++---- .../savestates/SavestateFile.cs | 3 +-- src/BizHawk.Client.Common/tools/CheatList.cs | 6 ++--- .../InputRoll/InputRoll.Drawing.cs | 26 ++++++------------- src/BizHawk.Client.EmuHawk/MainForm.cs | 4 +-- .../RetroAchievements.Hardcore.cs | 2 +- .../movie/EditCommentsForm.cs | 1 - src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs | 4 +-- .../tools/Cheats/Cheats.cs | 4 +-- .../tools/Debugger/BreakpointControl.cs | 4 +-- .../Debugger/GenericDebugger.Disassembler.cs | 2 +- .../tools/HexEditor/HexEditor.cs | 12 ++++----- .../tools/Lua/LuaConsole.cs | 18 ++++++------- .../tools/Lua/LuaRegisteredFunctionsList.cs | 2 +- .../tools/TAStudio/BookmarksBranchesBox.cs | 2 +- .../tools/TAStudio/MarkerControl.cs | 2 +- .../tools/TAStudio/TAStudio.cs | 3 ++- .../tools/TraceLogger.cs | 4 +-- .../tools/Watch/RamSearch.cs | 4 +-- .../tools/Watch/RamWatch.cs | 20 +++++--------- .../ControllerDefinition.cs | 4 +-- .../InputCallbackSystem.cs | 18 +++++-------- .../Hardware/Datacorder/DatacorderDevice.cs | 10 +------ .../Consoles/WonderSwan/WonderSwan.cs | 5 +--- 32 files changed, 92 insertions(+), 120 deletions(-) diff --git a/.global.editorconfig.ini b/.global.editorconfig.ini index 7eab8ff4f1..f1f228bc58 100644 --- a/.global.editorconfig.ini +++ b/.global.editorconfig.ini @@ -72,9 +72,20 @@ dotnet_diagnostic.CA1805.severity = silent # Mark members as static dotnet_diagnostic.CA1822.severity = silent # Use property instead of Linq Enumerable method +dotnet_diagnostic.CA1826.severity = error dotnet_code_quality.CA1826.exclude_ordefault_methods = true +# Do not use Count()/LongCount() when Any() can be used +dotnet_diagnostic.CA1827.severity = error +# Do not use CountAsync/LongCountAsync when AnyAsync can be used +dotnet_diagnostic.CA1828.severity = error +# Use Length/Count property instead of Enumerable.Count method +dotnet_diagnostic.CA1829.severity = error +# Prefer IsEmpty over Count when available +dotnet_diagnostic.CA1836.severity = error # Avoid StringBuilder parameters for P/Invokes dotnet_diagnostic.CA1838.severity = suggestion +# Avoid using 'Enumerable.Any()' extension method +dotnet_diagnostic.CA1860.severity = error # Use the 'StringComparison' method overloads to perform case-insensitive string comparisons dotnet_diagnostic.CA1862.severity = error @@ -344,7 +355,7 @@ dotnet_diagnostic.MA0109.severity = silent # Use the Regex source generator dotnet_diagnostic.MA0110.severity = error # Use 'Count > 0' instead of 'Any()' -dotnet_diagnostic.MA0112.severity = silent +dotnet_diagnostic.MA0112.severity = error # Raw String contains an implicit end of line character (if you compile on Windows you may get CRLFs in string literals) dotnet_diagnostic.MA0136.severity = warning # Both if and else branch have identical code @@ -405,6 +416,8 @@ dotnet_diagnostic.RCS1043.severity = warning dotnet_diagnostic.RCS1059.severity = silent # Avoid empty catch clause that catches System.Exception dotnet_diagnostic.RCS1075.severity = silent +# Use 'Count/Length' property instead of 'Any' method +dotnet_diagnostic.RCS1080.severity = error # Make class static dotnet_diagnostic.RCS1102.severity = silent # Add summary to documentation comment diff --git a/src/BizHawk.Client.Common/DisplayManager/OSDManager.cs b/src/BizHawk.Client.Common/DisplayManager/OSDManager.cs index 4382fadb83..8ba0bba9c1 100644 --- a/src/BizHawk.Client.Common/DisplayManager/OSDManager.cs +++ b/src/BizHawk.Client.Common/DisplayManager/OSDManager.cs @@ -137,7 +137,7 @@ namespace BizHawk.Client.Common _messages.RemoveAll(m => DateTime.Now > m.ExpireAt); - if (_messages.Any()) + if (_messages.Count is not 0) { if (_config.StackOSDMessages) { diff --git a/src/BizHawk.Client.Common/RecentFiles.cs b/src/BizHawk.Client.Common/RecentFiles.cs index 5313c3c4bf..af841a69de 100644 --- a/src/BizHawk.Client.Common/RecentFiles.cs +++ b/src/BizHawk.Client.Common/RecentFiles.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using BizHawk.Common.StringExtensions; @@ -32,15 +31,18 @@ namespace BizHawk.Client.Common public bool Frozen { get; set; } [JsonIgnore] - public bool Empty => !recentlist.Any(); + public bool Empty + => recentlist.Count is 0; [JsonIgnore] public int Count => recentlist.Count; [JsonIgnore] - public string MostRecent => recentlist.Any() ? recentlist[0] : ""; + public string MostRecent + => recentlist.Count is 0 ? string.Empty : recentlist[0]; - public string this[int index] => recentlist.Any() ? recentlist[index] : ""; + public string this[int index] + => recentlist.Count is 0 ? string.Empty : recentlist[index]; public IEnumerator GetEnumerator() => recentlist.GetEnumerator(); diff --git a/src/BizHawk.Client.Common/lua/LuaFunctionList.cs b/src/BizHawk.Client.Common/lua/LuaFunctionList.cs index c9640c655a..a5fdfc3ee7 100644 --- a/src/BizHawk.Client.Common/lua/LuaFunctionList.cs +++ b/src/BizHawk.Client.Common/lua/LuaFunctionList.cs @@ -12,6 +12,9 @@ namespace BizHawk.Client.Common private readonly Action Changed; + public int Count + => _functions.Count; + public LuaFunctionList(Action onChanged) => Changed = onChanged; public NamedLuaFunction this[string guid] diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.ModeApi.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.ModeApi.cs index 2b828388d3..0ad82bf082 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.ModeApi.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.ModeApi.cs @@ -1,6 +1,4 @@ -using System.Linq; - -namespace BizHawk.Client.Common +namespace BizHawk.Client.Common { public partial class Bk2Movie { @@ -9,7 +7,7 @@ namespace BizHawk.Client.Common public virtual void StartNewRecording() { Mode = MovieMode.Record; - if (Session.Settings.EnableBackupMovies && MakeBackup && Log.Any()) + if (MakeBackup && Session.Settings.EnableBackupMovies && Log.Count is not 0) { SaveBackup(); MakeBackup = false; diff --git a/src/BizHawk.Client.Common/movie/import/IMovieImport.cs b/src/BizHawk.Client.Common/movie/import/IMovieImport.cs index a20e7cda66..91a30f734f 100644 --- a/src/BizHawk.Client.Common/movie/import/IMovieImport.cs +++ b/src/BizHawk.Client.Common/movie/import/IMovieImport.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text.RegularExpressions; using BizHawk.Common; @@ -45,7 +44,7 @@ namespace BizHawk.Client.Common Result.Movie = session.Get(newFileName); RunImport(); - if (!Result.Errors.Any()) + if (Result.Errors.Count is 0) { if (string.IsNullOrEmpty(Result.Movie.Hash)) { diff --git a/src/BizHawk.Client.Common/movie/import/SmvImport.cs b/src/BizHawk.Client.Common/movie/import/SmvImport.cs index d00760f967..d265c54438 100644 --- a/src/BizHawk.Client.Common/movie/import/SmvImport.cs +++ b/src/BizHawk.Client.Common/movie/import/SmvImport.cs @@ -1,5 +1,4 @@ using System.IO; -using System.Linq; using System.Text; using BizHawk.Emulation.Common; @@ -289,7 +288,7 @@ namespace BizHawk.Client.Common.movie.import break; } - if (peripheral != "" && !Result.Warnings.Any()) + if (peripheral.Length is not 0 && Result.Warnings.Count is 0) { Result.Warnings.Add($"Unable to import {peripheral}. Not supported yet"); } diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs index 9aecad60a4..ac458581a9 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs @@ -107,7 +107,7 @@ namespace BizHawk.Client.Common public void RemoveFrames(ICollection frames) { - if (frames.Any()) + if (frames.Count is not 0) { // Separate the given frames into contiguous blocks // and process each block independently diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs index 5b5dc737a1..0690668a74 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs @@ -1,5 +1,4 @@ using System.IO; -using System.Linq; using BizHawk.Common.StringExtensions; @@ -33,15 +32,12 @@ namespace BizHawk.Client.Common bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(inputRollSettingsJson)); } - if (VerificationLog.Any()) + if (VerificationLog.Count is not 0) { bs.PutLump(BinaryStateLump.VerificationLog, tw => tw.WriteLine(VerificationLog.ToInputLog())); } - if (Branches.Any()) - { - Branches.Save(bs); - } + if (Branches.Count is not 0) Branches.Save(bs); bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(JsonConvert.SerializeObject(TasSession))); diff --git a/src/BizHawk.Client.Common/savestates/SavestateFile.cs b/src/BizHawk.Client.Common/savestates/SavestateFile.cs index a2af4d74a1..ba36bd5a4c 100644 --- a/src/BizHawk.Client.Common/savestates/SavestateFile.cs +++ b/src/BizHawk.Client.Common/savestates/SavestateFile.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using BizHawk.Bizware.Graphics; using BizHawk.Common; @@ -99,7 +98,7 @@ namespace BizHawk.Client.Common }); } - if (_userBag.Any()) + if (_userBag.Count is not 0) { bs.PutLump(BinaryStateLump.UserData, tw => diff --git a/src/BizHawk.Client.Common/tools/CheatList.cs b/src/BizHawk.Client.Common/tools/CheatList.cs index 493bc2568b..d40ee665e0 100644 --- a/src/BizHawk.Client.Common/tools/CheatList.cs +++ b/src/BizHawk.Client.Common/tools/CheatList.cs @@ -92,7 +92,7 @@ namespace BizHawk.Client.Common { _defaultFileName = defaultFileName; - if (_cheatList.Any() && _changes && autosave) + if (autosave && _changes && _cheatList.Count is not 0) { if (string.IsNullOrEmpty(CurrentFileName)) { @@ -224,7 +224,7 @@ namespace BizHawk.Client.Common { if (_config.AutoSaveOnClose) { - if (Changes && _cheatList.Any()) + if (Changes && _cheatList.Count is not 0) { if (string.IsNullOrWhiteSpace(CurrentFileName)) { @@ -233,7 +233,7 @@ namespace BizHawk.Client.Common SaveFile(CurrentFileName); } - else if (!_cheatList.Any() && !string.IsNullOrWhiteSpace(CurrentFileName)) + else if (_cheatList.Count is 0 && !string.IsNullOrWhiteSpace(CurrentFileName)) { File.Delete(CurrentFileName); _config.Recent.Remove(CurrentFileName); diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.Drawing.cs b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.Drawing.cs index cea79d1e6d..8c6fad39c7 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.Drawing.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.Drawing.cs @@ -43,8 +43,8 @@ namespace BizHawk.Client.EmuHawk var lastVisibleRow = firstVisibleRow + visibleRows; - var needsColumnRedraw = HorizontalOrientation || e.ClipRectangle.Y < ColumnHeight; - if (visibleColumns.Any() && needsColumnRedraw) + if (visibleColumns.Count is not 0 + && (HorizontalOrientation || e.ClipRectangle.Y < ColumnHeight)) { DrawColumnBg(visibleColumns, e.ClipRectangle); DrawColumnText(visibleColumns); @@ -214,11 +214,7 @@ namespace BizHawk.Client.EmuHawk { return; } - - if (!visibleColumns.Any()) - { - return; - } + if (visibleColumns.Count is 0) return; int startRow = firstVisibleRow; int range = Math.Min(lastVisibleRow, RowCount - 1) - startRow + 1; @@ -342,7 +338,7 @@ namespace BizHawk.Client.EmuHawk y += GetHColHeight(j); } - if (visibleColumns.Any()) + if (visibleColumns.Count is not 0) { _renderer.Line(1, y, MaxColumnWidth, y); } @@ -367,7 +363,7 @@ namespace BizHawk.Client.EmuHawk } // Draw right most line - if (visibleColumns.Any()) + if (visibleColumns.Count is not 0) { int right = TotalColWidth - _hBar.Value; if (right <= rect.Left + rect.Width) @@ -482,7 +478,7 @@ namespace BizHawk.Client.EmuHawk _renderer.Line(x, y, x, rect.Height - 1); } - if (visibleColumns.Any()) + if (visibleColumns.Count is not 0) { int x = TotalColWidth - _hBar.Value; _renderer.Line(x, y, x, rect.Height - 1); @@ -496,10 +492,7 @@ namespace BizHawk.Client.EmuHawk } } - if (_selectedItems.Any()) - { - DoSelectionBG(visibleColumns, rect); - } + if (_selectedItems.Count is not 0) DoSelectionBG(visibleColumns, rect); } private void DoSelectionBG(List visibleColumns, Rectangle rect) @@ -586,10 +579,7 @@ namespace BizHawk.Client.EmuHawk // Calls QueryItemBkColor callback for all visible cells and fills in the background of those cells. private void DoBackGroundCallback(List visibleColumns, Rectangle rect, int firstVisibleRow, int lastVisibleRow) { - if (!visibleColumns.Any()) - { - return; - } + if (visibleColumns.Count is 0) return; int startIndex = firstVisibleRow; int range = Math.Min(lastVisibleRow, RowCount - 1) - startIndex + 1; diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index b952f8aab5..83ab228915 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -4013,13 +4013,13 @@ namespace BizHawk.Client.EmuHawk { var result = MovieImport.ImportFile(this, MovieSession, fn, Config); - if (result.Errors.Any()) + if (result.Errors.Count is not 0) { ShowMessageBox(owner: null, string.Join("\n", result.Errors), "Conversion error", EMsgBoxIcon.Error); return; } - if (result.Warnings.Any()) + if (result.Warnings.Count is not 0) { AddOnScreenMessage(result.Warnings.First()); // For now, just show the first warning } diff --git a/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.Hardcore.cs b/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.Hardcore.cs index 5348a2cf27..382ca33d87 100644 --- a/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.Hardcore.cs +++ b/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.Hardcore.cs @@ -123,7 +123,7 @@ namespace BizHawk.Client.EmuHawk HandleHardcoreModeDisable("Using MAME in hardcore mode is not allowed."); break; case NymaCore nyma: - if (nyma.GetSettings().DisabledLayers.Any()) + if (nyma.GetSettings().DisabledLayers.Count is not 0) { HandleHardcoreModeDisable($"Disabling {Emu.GetType().Name}'s graphics layers in hardcore mode is not allowed."); } diff --git a/src/BizHawk.Client.EmuHawk/movie/EditCommentsForm.cs b/src/BizHawk.Client.EmuHawk/movie/EditCommentsForm.cs index 246034a471..0ddb2e07fa 100644 --- a/src/BizHawk.Client.EmuHawk/movie/EditCommentsForm.cs +++ b/src/BizHawk.Client.EmuHawk/movie/EditCommentsForm.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using System.Linq; using System.Windows.Forms; using BizHawk.Client.Common; diff --git a/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs b/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs index ef4a310762..c6d7292bc1 100644 --- a/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs +++ b/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs @@ -447,8 +447,8 @@ namespace BizHawk.Client.EmuHawk var framesItem = new ListViewItem("Frames"); framesItem.SubItems.Add(_movieList[firstIndex].FrameCount.ToString()); DetailsView.Items.Add(framesItem); - CommentsBtn.Enabled = _movieList[firstIndex].Comments.Any(); - SubtitlesBtn.Enabled = _movieList[firstIndex].Subtitles.Any(); + CommentsBtn.Enabled = _movieList[firstIndex].Comments.Count is not 0; + SubtitlesBtn.Enabled = _movieList[firstIndex].Subtitles.Count is not 0; } private void EditMenuItem_Click(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 0c6ed44be9..5a3b6531ca 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -400,7 +400,7 @@ namespace BizHawk.Client.EmuHawk private void RemoveCheatMenuItem_Click(object sender, EventArgs e) { var items = SelectedItems.ToList(); - if (items.Any()) + if (items.Count is not 0) { foreach (var item in items) { @@ -600,7 +600,7 @@ namespace BizHawk.Client.EmuHawk private void ViewInHexEditorContextMenuItem_Click(object sender, EventArgs e) { var selected = SelectedCheats.ToList(); - if (selected.Any()) + if (selected.Count is not 0) { Tools.Load(); diff --git a/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs b/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs index 5c095e4c04..49b41eb5d0 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs @@ -183,7 +183,7 @@ namespace BizHawk.Client.EmuHawk private void RemoveBreakpointButton_Click(object sender, EventArgs e) { var items = EditableItems.ToList(); - if (!items.Any()) return; + if (items.Count is 0) return; foreach (var item in items) _breakpoints.Remove(item); BreakpointView.VirtualListSize = _breakpoints.Count; UpdateBreakpointRemoveButton(); @@ -205,7 +205,7 @@ namespace BizHawk.Client.EmuHawk private void BreakpointView_ItemActivate(object sender, EventArgs e) { var items = EditableItems.ToList(); - if (!items.Any()) return; + if (items.Count is 0) return; foreach (var item in items) item.Active = !item.Active; BreakpointView.VirtualListSize = _breakpoints.Count; UpdateBreakpointRemoveButton(); diff --git a/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs b/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs index b8c881fa54..ea36b40c72 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs @@ -87,7 +87,7 @@ namespace BizHawk.Client.EmuHawk private void DisassemblerView_QueryItemBkColor(int index, RollColumn column, ref Color color) { - if (_disassemblyLines.Any() && index < _disassemblyLines.Count) + if (0 <= index && index < _disassemblyLines.Count) { if (_disassemblyLines[index].Address == _currentDisassemblerAddress) { diff --git a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index d844d71425..67dda4c144 100644 --- a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -281,7 +281,7 @@ namespace BizHawk.Client.EmuHawk DataSize = (int)size; SetDataSize(DataSize); var addrList = addresses.ToList(); - if (addrList.Any()) + if (addrList.Count is not 0) { SetMemoryDomain(domain.Name); SetHighlighted(addrList[0]); @@ -295,7 +295,7 @@ namespace BizHawk.Client.EmuHawk public byte[] ConvertTextToBytes(string str) { - if (_textTable.Any()) + if (_textTable.Count is not 0) { var byteArr = new byte[str.Length]; for (var i = 0; i < str.Length; i++) @@ -722,7 +722,7 @@ namespace BizHawk.Client.EmuHawk { var addressesString = "0x" + $"{_domain.Size / DataSize:X8}".TrimStart('0'); var viewerText = $"{Emulator.SystemId} {_domain}{(_domain.Writable ? string.Empty : " (READ-ONLY)")} - {addressesString} addresses"; - if (_nibbles.Any()) + if (_nibbles.Count is not 0) { viewerText += $" Typing: ({MakeNibbles()})"; } @@ -793,7 +793,7 @@ namespace BizHawk.Client.EmuHawk { var newTitle = "Hex Editor"; newTitle += " - Editing Address 0x" + string.Format(_numDigitsStr, _highlightedAddress); - if (_secondaryHighlightedAddresses.Any()) + if (_secondaryHighlightedAddresses.Count is not 0) { newTitle += $" (Selected 0x{_secondaryHighlightedAddresses.Count + (_secondaryHighlightedAddresses.Contains(_highlightedAddress.Value) ? 0 : 1):X})"; } @@ -880,7 +880,7 @@ namespace BizHawk.Client.EmuHawk MainForm.CheatList.RemoveRange(MainForm.CheatList.Where(x => x.Contains(_highlightedAddress.Value))); } - if (_secondaryHighlightedAddresses.Any()) + if (_secondaryHighlightedAddresses.Count is not 0) { MainForm.CheatList.RemoveRange( MainForm.CheatList.Where(cheat => !cheat.IsSeparator && cheat.Domain == _domain @@ -1241,7 +1241,7 @@ namespace BizHawk.Client.EmuHawk SaveAsBinaryMenuItem.Text = "Save as binary..."; } - CloseTableFileMenuItem.Enabled = _textTable.Any(); + CloseTableFileMenuItem.Enabled = _textTable.Count is not 0; } private void SaveMenuItem_Click(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index f0dcc800c9..3bcd750761 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -606,7 +606,7 @@ namespace BizHawk.Client.EmuHawk /// should frame waiters be waken up? only use this immediately before a frame of emulation public void ResumeScripts(bool includeFrameWaiters) { - if (!LuaImp.ScriptList.Any() + if (LuaImp.ScriptList.Count is 0 || LuaImp.IsUpdateSupressed || (MainForm.IsTurboing && !Config.RunLuaDuringTurbo)) { @@ -805,9 +805,9 @@ namespace BizHawk.Client.EmuHawk MoveDownMenuItem.Enabled = LuaListView.AnyRowsSelected; - SelectAllMenuItem.Enabled = LuaImp.ScriptList.Any(); + SelectAllMenuItem.Enabled = LuaImp.ScriptList.Count is not 0; StopAllScriptsMenuItem.Enabled = LuaImp.ScriptList.Any(script => script.Enabled); - RegisteredFunctionsMenuItem.Enabled = LuaImp.RegisteredFunctions.Any(); + RegisteredFunctionsMenuItem.Enabled = LuaImp.RegisteredFunctions.Count is not 0; } private void NewScriptMenuItem_Click(object sender, EventArgs e) @@ -943,7 +943,7 @@ namespace BizHawk.Client.EmuHawk private void RemoveScriptMenuItem_Click(object sender, EventArgs e) { var items = SelectedItems.ToList(); - if (items.Any()) + if (items.Count is not 0) { foreach (var item in items) { @@ -1069,7 +1069,7 @@ namespace BizHawk.Client.EmuHawk private void RegisteredFunctionsMenuItem_Click(object sender, EventArgs e) { - if (LuaImp.RegisteredFunctions.Any()) + if (LuaImp.RegisteredFunctions.Count is not 0) { var alreadyOpen = false; foreach (Form form in Application.OpenForms) @@ -1198,17 +1198,15 @@ namespace BizHawk.Client.EmuHawk ScriptContextSeparator.Visible = LuaImp.ScriptList.Exists(file => file.Enabled); - ClearRegisteredFunctionsContextItem.Enabled = - LuaImp.RegisteredFunctions.Any(); + ClearRegisteredFunctionsContextItem.Enabled = LuaImp.RegisteredFunctions.Count is not 0; } private void ConsoleContextMenu_Opening(object sender, CancelEventArgs e) { - RegisteredFunctionsContextItem.Enabled = LuaImp.RegisteredFunctions.Any(); + RegisteredFunctionsContextItem.Enabled = ClearRegisteredFunctionsLogContextItem.Enabled + = LuaImp.RegisteredFunctions.Count is not 0; CopyContextItem.Enabled = OutputBox.SelectedText.Length is not 0; ClearConsoleContextItem.Enabled = SelectAllContextItem.Enabled = OutputBox.Text.Length is not 0; - ClearRegisteredFunctionsLogContextItem.Enabled = - LuaImp.RegisteredFunctions.Any(); } private void ClearConsoleContextItem_Click(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs index 99183dfa58..9b1c7f2c47 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs @@ -120,7 +120,7 @@ namespace BizHawk.Client.EmuHawk var indexes = FunctionView.SelectedIndices; CallButton.Enabled = indexes.Count > 0; RemoveButton.Enabled = indexes.Count > 0; - RemoveAllBtn.Enabled = _registeredFunctions.Any(); + RemoveAllBtn.Enabled = _registeredFunctions.Count is not 0; } private void FunctionView_KeyDown(object sender, KeyEventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index 293bdd2957..c36c37904c 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -543,7 +543,7 @@ namespace BizHawk.Client.EmuHawk public void UpdateTextColumnWidth() { - if (Branches.Any()) + if (Branches.Count is not 0) { var longestBranchText = Branches .OrderBy(b => b.UserText?.Length ?? 0) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs index b8a8d720ae..633dfbb375 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs @@ -195,7 +195,7 @@ namespace BizHawk.Client.EmuHawk public void UpdateTextColumnWidth() { - if (Markers.Any()) + if (Markers.Count is not 0) { var longestBranchText = Markers .OrderBy(b => b.Message?.Length ?? 0) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 64fbff6637..ac7988b824 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -940,7 +940,8 @@ namespace BizHawk.Client.EmuHawk // TODO: columns selected? var selectedRowCount = TasView.SelectedRows.Count(); var temp = $"Selected: {selectedRowCount} {(selectedRowCount == 1 ? "frame" : "frames")}, States: {CurrentTasMovie.TasStateManager.Count}"; - if (_tasClipboard.Any()) temp += $", Clipboard: {_tasClipboard.Count} {(_tasClipboard.Count == 1 ? "frame" : "frames")}"; + var clipboardCount = _tasClipboard.Count; + if (clipboardCount is not 0) temp += $", Clipboard: {clipboardCount} {(clipboardCount is 1 ? "frame" : "frames")}"; SplicerStatusLabel.Text = temp; } diff --git a/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs b/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs index fbd279661e..7700a66dad 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs @@ -241,7 +241,7 @@ namespace BizHawk.Client.EmuHawk { TracerBox.Text = "Trace log - logging to file..."; } - else if (_instructions.Any()) + else if (_instructions.Count is not 0) { TracerBox.Text = $"Trace log - logging - {_instructions.Count} instructions"; } @@ -252,7 +252,7 @@ namespace BizHawk.Client.EmuHawk } else { - if (_instructions.Any()) + if (_instructions.Count is not 0) { TracerBox.Text = $"Trace log - {_instructions.Count} instructions"; } diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index e1e8137814..32a0fece67 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -812,7 +812,7 @@ namespace BizHawk.Client.EmuHawk private void RemoveAddresses() { var indices = SelectedIndices.ToList(); - if (indices.Any()) + if (indices.Count is not 0) { SetRemovedMessage(indices.Count); _searches.RemoveRange(indices); @@ -865,7 +865,7 @@ namespace BizHawk.Client.EmuHawk private void AddToRamWatch() { var watches = SelectedWatches.ToList(); - if (watches.Any()) + if (watches.Count is not 0) { Tools.LoadRamWatch(true); watches.ForEach(Tools.RamWatch.AddWatch); diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index b3cb6a3fdd..ab9bcf4824 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -327,7 +327,7 @@ namespace BizHawk.Client.EmuHawk return; } - if (_watches.Any()) + if (_watches.Count is not 0) { _watches.UpdateValues(Config.RamWatchDefinePrevious); DisplayOnScreenWatches(); @@ -342,7 +342,7 @@ namespace BizHawk.Client.EmuHawk } DisplayManager.OSD.ClearRamWatches(); - if (_watches.Any()) + if (_watches.Count is not 0) { _watches.UpdateValues(Config.RamWatchDefinePrevious); DisplayOnScreenWatches(); @@ -898,10 +898,7 @@ namespace BizHawk.Client.EmuHawk private void MoveUpMenuItem_Click(object sender, EventArgs e) { var indexes = SelectedIndices.ToList(); - if (!indexes.Any() || indexes[0] == 0) - { - return; - } + if (indexes is [ ] or [ 0, .. ]) return; foreach (var index in indexes) { @@ -954,10 +951,7 @@ namespace BizHawk.Client.EmuHawk private void MoveTopMenuItem_Click(object sender, EventArgs e) { var indexes = SelectedIndices.ToList(); - if (!indexes.Any()) - { - return; - } + if (indexes.Count is 0) return; for (int i = 0; i < indexes.Count; i++) { @@ -1177,7 +1171,7 @@ namespace BizHawk.Client.EmuHawk private void ViewInHexEditorContextMenuItem_Click(object sender, EventArgs e) { var selected = SelectedWatches.ToList(); - if (selected.Any()) + if (selected.Count is not 0) { Tools.Load(); ViewInHexEditor( @@ -1193,7 +1187,7 @@ namespace BizHawk.Client.EmuHawk { var selected = SelectedWatches.ToList(); - if (selected.Any()) + if (selected.Count is not 0) { var debugger = Tools.Load(); @@ -1208,7 +1202,7 @@ namespace BizHawk.Client.EmuHawk { var selected = SelectedWatches.ToList(); - if (selected.Any()) + if (selected.Count is not 0) { var debugger = Tools.Load(); diff --git a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index f676f2f036..6a8ef2282a 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -166,8 +166,6 @@ namespace BizHawk.Emulation.Common } public bool Any() - { - return BoolButtons.Any() || Axes.Any(); - } + => BoolButtons.Count is not 0 || Axes.Count is not 0; } } diff --git a/src/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs b/src/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs index ad0f30e82c..690975ab63 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; namespace BizHawk.Emulation.Common { @@ -21,33 +20,28 @@ namespace BizHawk.Emulation.Common // TODO: these just happen to be all the add/remove methods the client uses, to be thorough the others should be overriden as well public void RemoveAll(IEnumerable actions) { - var hadAny = this.Any(); - + var hadAny = Count is not 0; foreach (var action in actions) { Remove(action); } - - var hasAny = this.Any(); - + var hasAny = Count is not 0; Changes(hadAny, hasAny); } public new void Add(Action item) { - var hadAny = this.Any(); + var hadAny = Count is not 0; base.Add(item); - var hasAny = this.Any(); - + var hasAny = Count is not 0; Changes(hadAny, hasAny); } public new bool Remove(Action item) { - var hadAny = this.Any(); + var hadAny = Count is not 0; var result = base.Remove(item); - var hasAny = this.Any(); - + var hasAny = Count is not 0; Changes(hadAny, hasAny); return result; 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 468b25b28f..8fa372eed9 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Datacorder/DatacorderDevice.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Datacorder/DatacorderDevice.cs @@ -78,15 +78,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC private int _currentDataBlockIndex = 0; public int CurrentDataBlockIndex { - get - { - if (DataBlocks.Any()) - { - return _currentDataBlockIndex; - } - - return -1; - } + get => DataBlocks.Count is 0 ? -1 : _currentDataBlockIndex; set { if (value == _currentDataBlockIndex) { return; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs b/src/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs index 10cec3b421..16c701b705 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using BizHawk.Emulation.Common; @@ -180,9 +179,7 @@ namespace BizHawk.Emulation.Cores.WonderSwan } private void SetInputCallback() - { - BizSwan.bizswan_setbuttoncallback(Core, InputCallbacks.Any() ? ButtonCallbackD : null); - } + => BizSwan.bizswan_setbuttoncallback(Core, InputCallbacks.Count is 0 ? null : ButtonCallbackD); private void SetMemoryCallbacks() {