/// <summary> /// Feeds the target its required Apis. /// </summary> /// <returns>false if update failed</returns> public static bool UpdateApis(IExternalApiProvider source, object target) { Type targetType = target.GetType(); object[] tmp = new object[1]; targetType.GetProperties(ReflectionExtensions.DI_TARGET_PROPS).FirstOrDefault(pi => pi.PropertyType == typeof(ApiContainer)) ?.SetValue(target, source.Container); foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(RequiredApiAttribute))) { tmp[0] = source.GetApi(propinfo.PropertyType); if (tmp[0] == null) { return(false); } propinfo.GetSetMethod(true).Invoke(target, tmp); } foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(OptionalApiAttribute))) { tmp[0] = source.GetApi(propinfo.PropertyType); propinfo.GetSetMethod(true).Invoke(target, tmp); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="ToolManager"/> class. /// </summary> public ToolManager(MainForm owner, Config config, IEmulator emulator) { _owner = owner; _config = config; _emulator = emulator; _apiProvider = ApiManager.Restart(_emulator.ServiceProvider); }
/// <summary> /// Feeds the target its required Apis. /// </summary> /// <returns>false if update failed</returns> public static bool UpdateApis(IExternalApiProvider source, object target) { Type targetType = target.GetType(); object[] tmp = new object[1]; foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(RequiredApiAttribute))) { tmp[0] = source.GetApi(propinfo.PropertyType); if (tmp[0] == null) { return(false); } propinfo.GetSetMethod(true).Invoke(target, tmp); } foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(OptionalApiAttribute))) { tmp[0] = source.GetApi(propinfo.PropertyType); propinfo.GetSetMethod(true).Invoke(target, tmp); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="ToolManager"/> class. /// </summary> public ToolManager( MainForm owner, Config config, InputManager inputManager, IEmulator emulator, IMovieSession movieSession, IGameInfo game) { _owner = owner; _config = config; _inputManager = inputManager; _emulator = emulator; _movieSession = movieSession; _game = game; _apiProvider = ApiManager.Restart(_owner, _emulator.ServiceProvider); }
/// <summary> /// Determines whether a target is available, considering its dependencies /// and the Apis provided by the emulator core. /// </summary> public static bool IsAvailable(IExternalApiProvider source, Type targetType) { return(targetType.GetPropertiesWithAttrib(typeof(RequiredApiAttribute)) .Select(pi => pi.PropertyType) .All(source.HasApi)); }
public static T?GetApi <T>(this IExternalApiProvider apiProvider) where T : class, IExternalApi => apiProvider.GetApi(typeof(T)) as T;
public static bool HasApi <T>(this IExternalApiProvider apiProvider) where T : class, IExternalApi => apiProvider.HasApi(typeof(T));