Move required extension

This commit is contained in:
Matt Nadareski
2026-03-26 15:15:59 -04:00
parent 8356fc5970
commit 52ad2ff89c
2 changed files with 19 additions and 20 deletions

View File

@@ -859,25 +859,5 @@ namespace SabreTools.Data.Extensions
}
#endregion
#region Reading
/// <summary>
/// Read an item array from a given key, if possible
/// </summary>
public static T[]? ReadItemArray<T>(this DictionaryBase self, string key) where T : DictionaryBase
{
var items = self.Read<T[]>(key);
if (items == default)
{
var single = self.Read<T>(key);
if (single != default)
items = [single];
}
return items;
}
#endregion
}
}

View File

@@ -132,6 +132,25 @@ namespace SabreTools.Data.Models.Metadata
return this[key]!.ToString();
}
/// <summary>
/// Read a key as a T[], returning null on error
/// </summary>
public T[]? ReadArray<T>(string key)
{
if (!ValidateReadKey(key))
return null;
var items = Read<T[]>(key);
if (items is not null)
return items;
var single = Read<T>(key);
if (single is not null)
return [single];
return null;
}
/// <summary>
/// Read a key as a string[], returning null on error
/// </summary>