Fix minor logic bug in SetField

This commit is contained in:
Matt Nadareski
2024-10-24 06:15:57 -04:00
parent 29f6771845
commit 5ef99a1e53

View File

@@ -56,13 +56,18 @@ namespace SabreTools.Core.Filter
if (dictionaryBase == null || string.IsNullOrEmpty(fieldName))
return false;
// Retrieve the list of valid fields for the item and validate
// Retrieve the list of valid fields for the item
var constants = TypeHelper.GetConstants(dictionaryBase.GetType());
if (constants == null || !constants.Any(c => string.Equals(c, fieldName, StringComparison.OrdinalIgnoreCase)))
if (constants == null)
return false;
// Get the value that matches the field name provided
string? realField = constants.FirstOrDefault(c => string.Equals(c, fieldName, StringComparison.OrdinalIgnoreCase));
if (realField == null)
return false;
// Set the field with the new value
dictionaryBase[fieldName!] = value;
dictionaryBase[realField] = value;
return true;
}
}