コード例 #1
0
        /// <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);
        }
コード例 #2
0
 /// <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);
 }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
ファイル: ToolManager.cs プロジェクト: xHailFirex/BizHawk
 /// <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);
 }
コード例 #5
0
 /// <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));
 }
コード例 #6
0
 public static T?GetApi <T>(this IExternalApiProvider apiProvider)
     where T : class, IExternalApi
 => apiProvider.GetApi(typeof(T)) as T;
コード例 #7
0
 public static bool HasApi <T>(this IExternalApiProvider apiProvider)
     where T : class, IExternalApi
 => apiProvider.HasApi(typeof(T));