Enable MA0029 and fix noncompliance

"Combine LINQ methods"
This commit is contained in:
YoshiRulz 2022-07-21 01:22:24 +10:00
parent 26b6a1c4a9
commit b1ad34839a
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
10 changed files with 18 additions and 37 deletions

View File

@ -198,7 +198,7 @@
<Rule Id="MA0028" Action="Hidden" />
<!-- Combine LINQ methods -->
<Rule Id="MA0029" Action="Hidden" />
<Rule Id="MA0029" Action="Error" />
<!-- Remove useless OrderBy call -->
<Rule Id="MA0030" Action="Error" />

View File

@ -153,19 +153,10 @@ namespace BizHawk.Client.EmuHawk
ret.Nodes.Add(serviceNode);
}
var knownServices = Emulation.Common.ReflectionCache.Types
.Where(t => typeof(IEmulatorService).IsAssignableFrom(t))
.Where(t => t != typeof(IEmulatorService))
.Where(t => t != typeof(ITextStatable)) // Hack for now, eventually we can get rid of this interface in favor of a default implementation
.Where(t => t.IsInterface);
var additionalServices = knownServices
.Where(t => !ci.Services.ContainsKey(t.ToString()))
.Where(t => !ci.NotApplicableTypes.Contains(t.ToString()))
.Where(t => !typeof(ISpecializedEmulatorService).IsAssignableFrom(t)); // We don't want to show these as unimplemented, they aren't expected services
foreach (Type service in additionalServices)
foreach (var service in Emulation.Common.ReflectionCache.Types.Where(t => t.IsInterface
&& typeof(IEmulatorService).IsAssignableFrom(t) && !typeof(ISpecializedEmulatorService).IsAssignableFrom(t) // don't show ISpecializedEmulatorService subinterfaces as "missing" as there's no expectation that they'll be implemented eventually
&& t != typeof(IEmulatorService) && t != typeof(ITextStatable) // denylisting ITextStatable is a hack for now, eventually we can get merge it into IStatable w/ default interface methods
&& !ci.Services.ContainsKey(t.ToString()) && !ci.NotApplicableTypes.Contains(t.ToString())))
{
string img = "Bad";
var serviceNode = new TreeNode

View File

@ -33,8 +33,7 @@ namespace BizHawk.Client.EmuHawk
else
{
visibleColumns = _columns.VisibleColumns
.Where(c => c.Right > _hBar.Value)
.Where(c => c.Left - _hBar.Value < e.ClipRectangle.Width)
.Where(c => c.Right > _hBar.Value && c.Left - _hBar.Value < e.ClipRectangle.Width)
.ToList();
}

View File

@ -2070,8 +2070,8 @@ namespace BizHawk.Client.EmuHawk
}
private static readonly IList<Type> SpecializedTools = ReflectionCache.Types
.Where(t => typeof(IToolForm).IsAssignableFrom(t) && !t.IsAbstract)
.Where(t => t.GetCustomAttribute<SpecializedToolAttribute>() != null)
.Where(static t => !t.IsAbstract && typeof(IToolForm).IsAssignableFrom(t)
&& t.GetCustomAttribute<SpecializedToolAttribute>() is not null)
.ToList();
private ISet<char> _availableAccelerators;

View File

@ -1218,8 +1218,7 @@ namespace BizHawk.Client.EmuHawk
ColumnsSubMenu.DropDownItems.Clear();
var columns = TasView.AllColumns
.Where(c => !string.IsNullOrWhiteSpace(c.Text))
.Where(c => c.Name != "FrameColumn")
.Where(static c => !string.IsNullOrWhiteSpace(c.Text) && c.Name is not "FrameColumn")
.ToList();
int workingHeight = Screen.FromControl(this).WorkingArea.Height;

View File

@ -45,11 +45,10 @@ namespace BizHawk.Client.EmuHawk
ToolBoxStrip.Items.Clear();
var tools = EmuHawk.ReflectionCache.Types
.Where(t => typeof(IToolForm).IsAssignableFrom(t))
.Where(t => typeof(Form).IsAssignableFrom(t))
.Where(t => !typeof(ToolBox).IsAssignableFrom(t))
.Where(t => ServiceInjector.IsAvailable(Emulator.ServiceProvider, t))
.Where(t => VersionInfo.DeveloperBuild || !t.GetCustomAttributes(false).OfType<ToolAttribute>().Any(a => !a.Released));
.Where(t => typeof(IToolForm).IsAssignableFrom(t) && typeof(Form).IsAssignableFrom(t)
&& !typeof(ToolBox).IsAssignableFrom(t)
&& ServiceInjector.IsAvailable(Emulator.ServiceProvider, t)
&& (VersionInfo.DeveloperBuild || !t.GetCustomAttributes(false).OfType<ToolAttribute>().Any(static a => !a.Released)));
/*
for (int i = 0; i < tools.Count(); i++)

View File

@ -490,9 +490,7 @@ namespace BizHawk.Client.EmuHawk
}
public IEnumerable<Type> AvailableTools => EmuHawk.ReflectionCache.Types
.Where(t => typeof(IToolForm).IsAssignableFrom(t))
.Where(t => !t.IsInterface)
.Where(IsAvailable);
.Where(t => !t.IsInterface && typeof(IToolForm).IsAssignableFrom(t) && IsAvailable(t));
/// <summary>
/// Calls UpdateValues() on an instance of T, if it exists

View File

@ -570,7 +570,7 @@ namespace BizHawk.Client.EmuHawk
}
}
ErrorIconButton.Visible = _watches.Where(watch => !watch.IsSeparator).Any(watch => !watch.IsValid);
ErrorIconButton.Visible = _watches.Any(static watch => !watch.IsSeparator && !watch.IsValid);
MessageLabel.Text = message;
}

View File

@ -25,11 +25,8 @@ namespace BizHawk.Emulation.Common
// this also fully allows services that are not IEmulatorService
Type coreType = core.GetType();
var services = coreType.GetInterfaces()
.Where(t => typeof(IEmulatorService).IsAssignableFrom(t))
.Where(t => t != typeof(IEmulatorService) && t != typeof(ISpecializedEmulatorService));
foreach (Type service in services)
foreach (var service in coreType.GetInterfaces().Where(static t => typeof(IEmulatorService).IsAssignableFrom(t)
&& t != typeof(IEmulatorService) && t != typeof(ISpecializedEmulatorService)))
{
_services.Add(service, core);
}

View File

@ -69,9 +69,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
.ToArray();
var memoryDomains = _memoryAreas.Select(a => WaterboxMemoryDomain.Create(a, _exe)).ToList();
var primaryDomain = memoryDomains
.Where(md => md.Definition.Flags.HasFlag(LibWaterboxCore.MemoryDomainFlags.Primary))
.Single();
var primaryDomain = memoryDomains.Single(static md => md.Definition.Flags.HasFlag(LibWaterboxCore.MemoryDomainFlags.Primary));
var mdl = new MemoryDomainList(
memoryDomains.Cast<MemoryDomain>()