PKHeX/PKHeX.Core/Saves/Access/SaveBlockMetadata.cs
Kurt 4e87fd7eca Misc fixes
ty matt & foohyfooh
2024-03-04 23:46:11 -06:00

26 lines
768 B
C#

using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core;
/// <summary>
/// Utilizes Reflection to obtain all defined accessor property names and object values.
/// </summary>
/// <typeparam name="T">Type of accessor</typeparam>
public sealed class SaveBlockMetadata<T>
{
private readonly Dictionary<string, IDataIndirect> BlockList;
public SaveBlockMetadata(ISaveBlockAccessor<T> accessor)
{
var aType = accessor.GetType();
BlockList = aType.GetAllPropertiesOfType<IDataIndirect>(accessor);
}
public IEnumerable<string> GetSortedBlockList()
{
return BlockList.Select(z => z.Key).OrderBy(z => z);
}
public IDataIndirect GetBlock(string name) => BlockList.First(z => z.Key == name).Value;
}