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

27 lines
773 B
C#
Raw Normal View History

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