Also check non-public `ApiContainer` properties when injecting APIs
This commit is contained in:
parent
aa135fc0dd
commit
71150c60d3
|
@ -35,7 +35,7 @@ namespace BizHawk.Client.Common
|
|||
Type targetType = target.GetType();
|
||||
object[] tmp = new object[1];
|
||||
|
||||
targetType.GetProperties().FirstOrDefault(pi => pi.PropertyType == typeof(ApiContainer))
|
||||
targetType.GetProperties(ReflectionExtensions.DI_TARGET_PROPS).FirstOrDefault(pi => pi.PropertyType == typeof(ApiContainer))
|
||||
?.SetValue(target, source.Container);
|
||||
|
||||
foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(RequiredApiAttribute)))
|
||||
|
|
|
@ -11,15 +11,18 @@ namespace BizHawk.Common.ReflectionExtensions
|
|||
/// </summary>
|
||||
public static class ReflectionExtensions
|
||||
{
|
||||
/// <summary>filter used when looking for <c>[RequiredApi]</c> et al. by reflection for dependency injection</summary>
|
||||
public const BindingFlags DI_TARGET_PROPS = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
|
||||
|
||||
public static IEnumerable<PropertyInfo> GetPropertiesWithAttrib(this Type type, Type attributeType)
|
||||
{
|
||||
return type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
return type.GetProperties(DI_TARGET_PROPS)
|
||||
.Where(p => p.GetCustomAttributes(attributeType, false).Length > 0);
|
||||
}
|
||||
|
||||
public static IEnumerable<MethodInfo> GetMethodsWithAttrib(this Type type, Type attributeType)
|
||||
{
|
||||
return type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
return type.GetMethods(DI_TARGET_PROPS)
|
||||
.Where(p => p.GetCustomAttributes(attributeType, false).Length > 0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue