Fix null ref

This commit is contained in:
Cj 2024-06-23 17:17:27 -04:00
parent f5b14da70b
commit 3985129549
2 changed files with 12 additions and 7 deletions

View File

@ -41,7 +41,7 @@ public partial class ReCodeItForm : Form
LoadMappingFile(); LoadMappingFile();
var remaps = AppSettings.Remapper.UseProjectMappings var remaps = AppSettings.Remapper.UseProjectMappings
? CrossCompiler.ActiveProject.RemapModels ? CrossCompiler.ActiveProject?.RemapModels
: DataProvider.Remaps; : DataProvider.Remaps;
ReloadRemapTreeView(remaps); ReloadRemapTreeView(remaps);
@ -1319,11 +1319,16 @@ public partial class ReCodeItForm : Form
/// Subscribes the the remappers OnComplete event /// Subscribes the the remappers OnComplete event
/// </summary> /// </summary>
/// <param name="remaps"></param> /// <param name="remaps"></param>
private void ReloadRemapTreeView(List<RemapModel> remaps) private void ReloadRemapTreeView(List<RemapModel>? remaps)
{ {
RemapTreeView.Nodes.Clear(); RemapTreeView.Nodes.Clear();
RemapNodes.Clear(); RemapNodes.Clear();
if (remaps is null)
{
return;
}
foreach (var remap in remaps) foreach (var remap in remaps)
{ {
RemapTreeView.Nodes.Add(GUIHelpers.GenerateTreeNode(remap, this)); RemapTreeView.Nodes.Add(GUIHelpers.GenerateTreeNode(remap, this));

View File

@ -1,5 +1,5 @@
using Mono.Cecil; using Mono.Cecil;
using Mono.Collections.Generic; using Mono.Cecil.Rocks;
using ReCodeIt.Models; using ReCodeIt.Models;
using ReCodeIt.Utils; using ReCodeIt.Utils;
@ -15,7 +15,7 @@ internal static class RenameHelper
/// <param name="score"></param> /// <param name="score"></param>
public static void RenameAll(ScoringModel score, bool direct = false) public static void RenameAll(ScoringModel score, bool direct = false)
{ {
var types = DataProvider.ModuleDefinition.Types; var types = DataProvider.ModuleDefinition.GetAllTypes();
// Rename all fields and properties first // Rename all fields and properties first
if (DataProvider.Settings.Remapper.MappingSettings.RenameFields) if (DataProvider.Settings.Remapper.MappingSettings.RenameFields)
@ -60,7 +60,7 @@ internal static class RenameHelper
public static int RenameAllFields( public static int RenameAllFields(
string oldTypeName, string oldTypeName,
string newTypeName, string newTypeName,
Collection<TypeDefinition> typesToCheck, IEnumerable<TypeDefinition> typesToCheck,
int overAllCount = 0) int overAllCount = 0)
{ {
foreach (var type in typesToCheck) foreach (var type in typesToCheck)
@ -108,7 +108,7 @@ internal static class RenameHelper
public static int RenameAllProperties( public static int RenameAllProperties(
string oldTypeName, string oldTypeName,
string newTypeName, string newTypeName,
Collection<TypeDefinition> typesToCheck, IEnumerable<TypeDefinition> typesToCheck,
int overAllCount = 0) int overAllCount = 0)
{ {
foreach (var type in typesToCheck) foreach (var type in typesToCheck)
@ -157,7 +157,7 @@ internal static class RenameHelper
return propertyCount > 0 ? $"{newName}_{propertyCount}" : newName; return propertyCount > 0 ? $"{newName}_{propertyCount}" : newName;
} }
private static void RenameType(Collection<TypeDefinition> typesToCheck, ScoringModel score) private static void RenameType(IEnumerable<TypeDefinition> typesToCheck, ScoringModel score)
{ {
foreach (var type in typesToCheck) foreach (var type in typesToCheck)
{ {