PKHeX/PKHeX.Core/Saves/Access/SaveBlockMetadata.cs

27 lines
768 B
C#
Raw Normal View History

using System.Collections.Generic;
2020-04-26 16:23:06 -07:00
using System.Linq;
namespace PKHeX.Core;
2020-04-26 16:23:06 -07:00
/// <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>
{
2024-03-04 23:46:11 -06:00
private readonly Dictionary<string, IDataIndirect> BlockList;
2020-04-26 16:23:06 -07:00
public SaveBlockMetadata(ISaveBlockAccessor<T> accessor)
{
var aType = accessor.GetType();
BlockList = aType.GetAllPropertiesOfType<IDataIndirect>(accessor);
}
2020-04-26 16:23:06 -07:00
public IEnumerable<string> GetSortedBlockList()
{
2024-03-04 23:46:11 -06:00
return BlockList.Select(z => z.Key).OrderBy(z => z);
2020-04-26 16:23:06 -07:00
}
2024-03-04 23:46:11 -06:00
public IDataIndirect GetBlock(string name) => BlockList.First(z => z.Key == name).Value;
2020-04-26 16:23:06 -07:00
}