mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-23 15:24:56 +00:00
Minor Linq reduction
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SabreTools.Models.Listrom;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
@@ -58,14 +57,19 @@ namespace SabreTools.Serialization.CrossModel
|
||||
|
||||
if (item.Row != null && item.Row.Length > 0)
|
||||
{
|
||||
var datItems = new List<Models.Metadata.DatItem>();
|
||||
var disks = new List<Models.Metadata.Disk>();
|
||||
var roms = new List<Models.Metadata.Rom>();
|
||||
foreach (var file in item.Row)
|
||||
{
|
||||
datItems.Add(ConvertToInternalModel(file));
|
||||
var datItem = ConvertToInternalModel(file);
|
||||
if (datItem is Models.Metadata.Disk disk)
|
||||
disks.Add(disk);
|
||||
else if (datItem is Models.Metadata.Rom rom)
|
||||
roms.Add(rom);
|
||||
}
|
||||
|
||||
machine[Models.Metadata.Machine.DiskKey] = datItems.Where(i => i.ReadString(Models.Metadata.DatItem.TypeKey) == "disk").Select(d => d as Models.Metadata.Disk).ToArray();
|
||||
machine[Models.Metadata.Machine.RomKey] = datItems.Where(i => i.ReadString(Models.Metadata.DatItem.TypeKey) == "rom").Select(d => d as Models.Metadata.Rom).ToArray();
|
||||
machine[Models.Metadata.Machine.DiskKey] = disks.ToArray();
|
||||
machine[Models.Metadata.Machine.RomKey] = roms.ToArray();
|
||||
}
|
||||
|
||||
return machine;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.BSP;
|
||||
@@ -165,9 +164,9 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// TODO: Use marshalling here instead of building
|
||||
var texture = new Texture();
|
||||
|
||||
byte[]? name = data.ReadBytes(16)?.TakeWhile(c => c != '\0')?.ToArray();
|
||||
byte[]? name = data.ReadBytes(16);
|
||||
if (name != null)
|
||||
texture.Name = Encoding.ASCII.GetString(name);
|
||||
texture.Name = Encoding.ASCII.GetString(name).TrimEnd('\0');
|
||||
texture.Width = data.ReadUInt32();
|
||||
texture.Height = data.ReadUInt32();
|
||||
texture.Offsets = new uint[4];
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
@@ -108,12 +107,13 @@ namespace SabreTools.Serialization.Deserializers
|
||||
if (deserializerName == null)
|
||||
return default;
|
||||
|
||||
// If the deserializer has no model type
|
||||
Type? modelType = typeof(TDeserializer).GetGenericArguments()?.FirstOrDefault();
|
||||
if (modelType == null)
|
||||
// If the deserializer has no generic arguments
|
||||
var genericArgs = typeof(TDeserializer).GetGenericArguments();
|
||||
if (genericArgs.Length == 0)
|
||||
return default;
|
||||
|
||||
// Loop through all loaded assemblies
|
||||
Type modelType = genericArgs[0];
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
// If the assembly is invalid
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Read and split the line
|
||||
string? line = reader.ReadLine();
|
||||
#if NETFRAMEWORK || NETCOREAPP3_1
|
||||
string[]? lineParts = line?.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[]? lineParts = line?.Split([' '], StringSplitOptions.RemoveEmptyEntries);
|
||||
#else
|
||||
string[]? lineParts = line?.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
#endif
|
||||
|
||||
@@ -1047,7 +1047,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|| importTable.ImportAddressTables != null && importTable.ImportAddressTables.Count > 0)
|
||||
{
|
||||
// Get the addresses of the hint/name table entries
|
||||
List<int> hintNameTableEntryAddresses = new List<int>();
|
||||
var hintNameTableEntryAddresses = new List<int>();
|
||||
|
||||
// If we have import lookup tables
|
||||
if (importTable.ImportLookupTables != null && importLookupTables.Count > 0)
|
||||
|
||||
Reference in New Issue
Block a user