2020-02-09 08:25:21 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace LibHac.Tests
|
|
|
|
|
{
|
|
|
|
|
internal class ResultNameResolver : Result.IResultNameResolver
|
|
|
|
|
{
|
|
|
|
|
private Lazy<Dictionary<Result, string>> ResultNames { get; } = new Lazy<Dictionary<Result, string>>(GetResultNames);
|
|
|
|
|
|
|
|
|
|
public bool TryResolveName(Result result, out string name)
|
|
|
|
|
{
|
|
|
|
|
return ResultNames.Value.TryGetValue(result, out name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Dictionary<Result, string> GetResultNames()
|
|
|
|
|
{
|
|
|
|
|
var dict = new Dictionary<Result, string>();
|
|
|
|
|
|
|
|
|
|
Assembly assembly = typeof(Result).Assembly;
|
|
|
|
|
|
|
|
|
|
foreach (TypeInfo type in assembly.DefinedTypes.Where(x => x.Name.Contains("Result")))
|
|
|
|
|
foreach (PropertyInfo property in type.DeclaredProperties
|
2020-05-13 02:06:55 +02:00
|
|
|
|
.Where(x => x.PropertyType == typeof(Result.Base) && x.GetMethod?.IsStatic == true && x.SetMethod == null))
|
2020-02-09 08:25:21 +01:00
|
|
|
|
{
|
2020-05-13 02:06:55 +02:00
|
|
|
|
object value = property.GetValue(null, null);
|
|
|
|
|
if (value is null) continue;
|
|
|
|
|
|
|
|
|
|
Result resultValue = ((Result.Base)value).Value;
|
2020-02-09 08:25:21 +01:00
|
|
|
|
string name = $"{type.Name}{property.Name}";
|
|
|
|
|
|
2020-05-13 02:06:55 +02:00
|
|
|
|
dict[resultValue] = name;
|
2020-02-09 08:25:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|