Reduce Linq usage across entire project

This commit is contained in:
Matt Nadareski
2024-10-19 21:41:08 -04:00
parent 1c079aab18
commit b87b05f828
36 changed files with 215 additions and 205 deletions

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using SabreTools.Core;
using SabreTools.DatItems;
@@ -126,7 +125,7 @@ namespace SabreTools.DatFiles.Formats
continue;
// Resolve the names in the block
items = DatItem.ResolveNamesDB(items.ToConcurrentList()).ToArray();
items = [.. DatItem.ResolveNamesDB(items.ToConcurrentList())];
for (int index = 0; index < items.Length; index++)
{

View File

@@ -113,11 +113,11 @@ namespace SabreTools.DatFiles.Formats
// Read in the machine array
jtr.Read();
JsonSerializer js = new();
JArray? machineArray = js.Deserialize<JArray>(jtr);
var js = new JsonSerializer();
JArray machineArray = js.Deserialize<JArray>(jtr) ?? [];
// Loop through each machine object and process
foreach (JObject machineObj in (machineArray ?? []).Cast<JObject>())
foreach (JObject machineObj in machineArray)
{
ReadMachine(machineObj, statsOnly, source, sourceIndex);
}
@@ -179,7 +179,7 @@ namespace SabreTools.DatFiles.Formats
return;
// Loop through each datitem object and process
foreach (JObject itemObj in itemsArr.Cast<JObject>())
foreach (JObject itemObj in itemsArr)
{
ReadItem(itemObj, statsOnly, source, sourceIndex, machine, machineIndex);
}
@@ -480,7 +480,7 @@ namespace SabreTools.DatFiles.Formats
continue;
// Resolve the names in the block
items = DatItem.ResolveNamesDB(items.ToConcurrentList()).ToArray();
items = [.. DatItem.ResolveNamesDB(items.ToConcurrentList())];
for (int index = 0; index < items.Length; index++)
{

View File

@@ -1,6 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
@@ -310,7 +309,7 @@ namespace SabreTools.DatFiles.Formats
continue;
// Resolve the names in the block
items = DatItem.ResolveNamesDB(items.ToConcurrentList()).ToArray();
items = [.. DatItem.ResolveNamesDB(items.ToConcurrentList())];
for (int index = 0; index < items.Length; index++)
{

View File

@@ -122,9 +122,10 @@ namespace SabreTools.DatFiles.Formats
missingFields.Add(Models.Metadata.DipSwitch.MaskKey);
if (dipSwitch.ValuesSpecified)
{
if (dipSwitch.GetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey)!.Any(dv => string.IsNullOrEmpty(dv.GetName())))
var dipValues = dipSwitch.GetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey);
if (dipValues!.Any(dv => string.IsNullOrEmpty(dv.GetName())))
missingFields.Add(Models.Metadata.DipValue.NameKey);
if (dipSwitch.GetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey)!.Any(dv => string.IsNullOrEmpty(dv.GetStringFieldValue(Models.Metadata.DipValue.ValueKey))))
if (dipValues!.Any(dv => string.IsNullOrEmpty(dv.GetStringFieldValue(Models.Metadata.DipValue.ValueKey))))
missingFields.Add(Models.Metadata.DipValue.ValueKey);
}