예제 #1
0
        private static void RunStartupFunctions(ProjectManifest projectManifest, AssemblyLoadSystem als, Game game)
        {
            foreach (var function in projectManifest.GameStartupFunctions)
            {
                Type t;
                if (!als.TryGetType(function.TypeName, out t))
                {
                    t = Type.GetType(function.TypeName);
                    if (t == null)
                    {
                        throw new InvalidOperationException("Invalid type name listed in project manifest's startup functions: " + function.TypeName);
                    }
                }

                MethodInfo mi = t.GetMethod(function.MethodName);
                if (mi == null)
                {
                    throw new InvalidOperationException("Invalid method name listed in startup function for type " + function.TypeName + ". Function name = " + function.MethodName);
                }

                var parameters = mi.GetParameters();
                if (parameters.Length != 1 || parameters[0].ParameterType != typeof(Game))
                {
                    throw new InvalidOperationException("Startup function must be a static method accepting one parameter of type Engine.Game");
                }

                mi.Invoke(null, new[] { game });
            }
        }
예제 #2
0
        public static bool TryGetType(AssemblyLoadSystem als, string typeName, out Type type)
        {
            if (!als.TryGetType(typeName, out type))
            {
                type = Type.GetType(typeName);
            }

            return(type != null);
        }