mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make some consistency updates to ItemDictionary
This commit is contained in:
@@ -120,7 +120,7 @@ namespace SabreTools.DatFiles
|
|||||||
lock (key)
|
lock (key)
|
||||||
{
|
{
|
||||||
// Ensure the key exists
|
// Ensure the key exists
|
||||||
EnsureKey(key);
|
EnsureBucketingKey(key);
|
||||||
|
|
||||||
// If item is null, don't add it
|
// If item is null, don't add it
|
||||||
if (value == null)
|
if (value == null)
|
||||||
@@ -149,7 +149,7 @@ namespace SabreTools.DatFiles
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Ensure the key exists
|
// Ensure the key exists
|
||||||
EnsureKey(key);
|
EnsureBucketingKey(key);
|
||||||
|
|
||||||
// Now add the value
|
// Now add the value
|
||||||
_items[key]!.AddRange(value);
|
_items[key]!.AddRange(value);
|
||||||
@@ -251,7 +251,7 @@ namespace SabreTools.DatFiles
|
|||||||
// If only adding statistics, we add an empty key for games and then just item stats
|
// If only adding statistics, we add an empty key for games and then just item stats
|
||||||
if (statsOnly)
|
if (statsOnly)
|
||||||
{
|
{
|
||||||
EnsureKey(key);
|
EnsureBucketingKey(key);
|
||||||
DatStatistics.AddItemStatistics(item);
|
DatStatistics.AddItemStatistics(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -364,13 +364,13 @@ namespace SabreTools.DatFiles
|
|||||||
/// Ensure the key exists in the items dictionary
|
/// Ensure the key exists in the items dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key">Key to ensure</param>
|
/// <param name="key">Key to ensure</param>
|
||||||
public void EnsureKey(string key)
|
public void EnsureBucketingKey(string key)
|
||||||
{
|
{
|
||||||
// If the key is missing from the dictionary, add it
|
// If the key is missing from the dictionary, add it
|
||||||
if (!_items.ContainsKey(key))
|
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
_items.TryAdd(key, []);
|
_items.GetOrAdd(key, []);
|
||||||
#else
|
#else
|
||||||
|
if (!_items.ContainsKey(key))
|
||||||
_items[key] = [];
|
_items[key] = [];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -383,10 +383,16 @@ namespace SabreTools.DatFiles
|
|||||||
if (bucketName == null)
|
if (bucketName == null)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
if (!_items.TryGetValue(bucketName, out var items))
|
||||||
|
return [];
|
||||||
|
#else
|
||||||
if (!_items.ContainsKey(bucketName))
|
if (!_items.ContainsKey(bucketName))
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
var items = _items[bucketName];
|
var items = _items[bucketName];
|
||||||
|
#endif
|
||||||
|
|
||||||
if (items == null)
|
if (items == null)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user