From 70a7bd7775f828ae4031bbe56ca4de5613b72ba2 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 6 Sep 2020 12:25:18 -0700 Subject: [PATCH] Minor clean no functional change --- NHSE.Core/Util/ReflectUtil.cs | 4 ++-- NHSE.Parsing/GameMSBTDumper.cs | 10 ++++------ NHSE.Parsing/GameMSBTDumperNHSE.cs | 10 +++++----- NHSE.WinForms/Main.cs | 2 +- NHSE.WinForms/Util/WinFormsUtil.cs | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/NHSE.Core/Util/ReflectUtil.cs b/NHSE.Core/Util/ReflectUtil.cs index a4580f8..df34726 100644 --- a/NHSE.Core/Util/ReflectUtil.cs +++ b/NHSE.Core/Util/ReflectUtil.cs @@ -125,14 +125,14 @@ private static IEnumerable GetAll(this TypeInfo typeInfo, Func accessor(typeInfo)); } - public static Dictionary GetAllConstantsOfType(this Type type) + public static Dictionary GetAllConstantsOfType(this Type type) where T : struct { var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy); var consts = fields.Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(T)); return consts.ToDictionary(x => (T)x.GetRawConstantValue(), z => z.Name); } - public static Dictionary GetAllPropertiesOfType(this Type type, object obj) + public static Dictionary GetAllPropertiesOfType(this Type type, object obj) where T : class { var props = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); var ofType = props.Where(fi => typeof(T).IsAssignableFrom(fi.PropertyType)); diff --git a/NHSE.Parsing/GameMSBTDumper.cs b/NHSE.Parsing/GameMSBTDumper.cs index af56994..c6405aa 100644 --- a/NHSE.Parsing/GameMSBTDumper.cs +++ b/NHSE.Parsing/GameMSBTDumper.cs @@ -12,18 +12,16 @@ public static string[] GetItemListResource(string msgPath) { var list = GetItemList(msgPath); var max = list.Max(z => z.Key); - var result = new string[max + 1]; + var result = new string?[max + 1]; foreach (var item in list) result[item.Key] = item.Value; for (int i = 0; i < result.Length; i++) - { - if (result[i] == null) - result[i] = string.Empty; - } + result[i] ??= string.Empty; + result[0] = "(None)"; result[5794] = "DIY recipe"; - return result; + return result!; } public static string[] GetArtList(string msgPath) diff --git a/NHSE.Parsing/GameMSBTDumperNHSE.cs b/NHSE.Parsing/GameMSBTDumperNHSE.cs index 2c4a94c..ae9ac1d 100644 --- a/NHSE.Parsing/GameMSBTDumperNHSE.cs +++ b/NHSE.Parsing/GameMSBTDumperNHSE.cs @@ -65,11 +65,11 @@ private static void DumpItem(string corePath, string langID, string msbtFolder, private static void DumpRemake(string corePath, string langID, string msbtFolder, string langFolderCode) { - Dump("body_color", "STR_Remake_BodyColor.msbt"); - Dump("body_parts", "STR_Remake_BodyParts.msbt"); - Dump("fabric_color", "STR_Remake_FabricColor.msbt"); - Dump("fabric_parts", "STR_Remake_FabricParts.msbt"); - void Dump(string name, string msbt) + DumpMSBT("body_color", "STR_Remake_BodyColor.msbt"); + DumpMSBT("body_parts", "STR_Remake_BodyParts.msbt"); + DumpMSBT("fabric_color", "STR_Remake_FabricColor.msbt"); + DumpMSBT("fabric_parts", "STR_Remake_FabricParts.msbt"); + void DumpMSBT(string name, string msbt) { var dest = Path.Combine(corePath, langID, $"text_{name}_{langID}.txt"); var folder = string.Format(msbtFolder, langFolderCode); diff --git a/NHSE.WinForms/Main.cs b/NHSE.WinForms/Main.cs index 707688f..2a81fc8 100644 --- a/NHSE.WinForms/Main.cs +++ b/NHSE.WinForms/Main.cs @@ -57,7 +57,7 @@ private void Main_DragEnter(object sender, DragEventArgs e) private void Main_DragDrop(object sender, DragEventArgs e) { - string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + var files = (string[]?)e.Data.GetData(DataFormats.FileDrop); if (files == null || files.Length == 0) return; Open(files[0]); diff --git a/NHSE.WinForms/Util/WinFormsUtil.cs b/NHSE.WinForms/Util/WinFormsUtil.cs index 4813efd..e951f0c 100644 --- a/NHSE.WinForms/Util/WinFormsUtil.cs +++ b/NHSE.WinForms/Util/WinFormsUtil.cs @@ -64,7 +64,7 @@ internal static DialogResult Prompt(MessageBoxButtons btn, params string[] lines /// Gets the selected value of the input . If no value is selected, will return 0. /// /// ComboBox to retrieve value for. - internal static int GetIndex(ListControl cb) => (int)(cb?.SelectedValue ?? 0); + internal static int GetIndex(ListControl cb) => (int)(cb.SelectedValue ?? 0); public static T? FirstFormOfType() where T : Form => (T?)Application.OpenForms.Cast
().FirstOrDefault(form => form is T);