Minor clean

no functional change
This commit is contained in:
Kurt
2020-09-06 12:25:18 -07:00
parent a2ed2889a2
commit 70a7bd7775
5 changed files with 13 additions and 15 deletions

View File

@@ -125,14 +125,14 @@ private static IEnumerable<T> GetAll<T>(this TypeInfo typeInfo, Func<TypeInfo, I
return GetAllTypeInfo(typeInfo).SelectMany(_ => accessor(typeInfo));
}
public static Dictionary<T, string> GetAllConstantsOfType<T>(this Type type)
public static Dictionary<T, string> GetAllConstantsOfType<T>(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<T, string> GetAllPropertiesOfType<T>(this Type type, object obj)
public static Dictionary<T, string> GetAllPropertiesOfType<T>(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));

View File

@@ -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)

View File

@@ -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);

View File

@@ -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]);

View File

@@ -64,7 +64,7 @@ internal static DialogResult Prompt(MessageBoxButtons btn, params string[] lines
/// Gets the selected value of the input <see cref="cb"/>. If no value is selected, will return 0.
/// </summary>
/// <param name="cb">ComboBox to retrieve value for.</param>
internal static int GetIndex(ListControl cb) => (int)(cb?.SelectedValue ?? 0);
internal static int GetIndex(ListControl cb) => (int)(cb.SelectedValue ?? 0);
public static T? FirstFormOfType<T>() where T : Form => (T?)Application.OpenForms.Cast<Form>().FirstOrDefault(form => form is T);