gbrainy.Core.Main.GameManager.LoadAssemblyGames C# (CSharp) Method

LoadAssemblyGames() public method

public LoadAssemblyGames ( string file ) : void
file string
return void
        public void LoadAssemblyGames(string file)
        {
            const string CLASS = "gbrainy.Games.GameList";
            const string LOGIC_METHOD = "LogicPuzzles";
            const string CALCULATION_METHOD = "Calculation";
            const string MEMORY_METHOD = "Memory";

            Assembly asem;
            Type type = null;
            PropertyInfo prop;
            object obj;

            try
            {
                if (domain_load == false)
                {
                    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler (ResolveAssemblyLoad);
                    domain_load = true;
                }

                asem = Assembly.Load (file);

                foreach (Type t in asem.GetTypes())
                {
                    if (t.FullName == CLASS)
                    {
                        type = t;
                        break;
                    }
                }

                obj = Activator.CreateInstance (type);

                prop = type.GetProperty (LOGIC_METHOD);
                if (prop != null)
                    cnt_logic += AddGamesAndVariations ((Type []) prop.GetValue (obj, null));

                prop = type.GetProperty (MEMORY_METHOD);
                if (prop != null)
                    cnt_memory += AddGamesAndVariations ((Type []) prop.GetValue (obj, null));

                prop = type.GetProperty (CALCULATION_METHOD);
                if (prop != null)
                    cnt_calculation += AddGamesAndVariations ((Type []) prop.GetValue (obj, null));
            }

            catch (Exception e)
            {
                Console.WriteLine ("GameManager.LoadAssemblyGames. Could not load file {0}. Error {1}", file, e);
            }
        }

Usage Example

Example #1
0
 public static void GameManagerPreload(GameManager gm)
 {
     gm.LoadAssemblyGames (Defines.GAME_ASSEMBLY);
     gm.LoadVerbalAnalogies (System.IO.Path.Combine (Defines.DATA_DIR, Defines.VERBAL_ANALOGIES));
     gm.LoadGamesFromXml (System.IO.Path.Combine (Defines.DATA_DIR, Defines.GAMES_FILE));
     gm.LoadPlugins ();
 }
All Usage Examples Of gbrainy.Core.Main.GameManager::LoadAssemblyGames