Sharpex2D.InitializeHelper.GetGameClass C# (CSharp) Метод

GetGameClass() публичный статический Метод

Gets the Game class.
public static GetGameClass ( ) : Game
Результат Game
        public static Game GetGameClass()
        {
            Type[] types = Assembly.GetEntryAssembly().GetTypes();

            foreach (Type type in types.Where(type => type.BaseType == typeof (Game)))
            {
                try
                {
                    return (Game) Activator.CreateInstance(type);
                }
                catch (Exception ex)
                {
                    LogManager.GetClassLogger().Error(
                        "Failed to initialize constructor of {0}. Parameters at constructor are not supported.",
                        type.Name);

                    throw new TargetInvocationException(ex);
                }
            }

            throw new InvalidOperationException("The game class was not found.");
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Initializes SGL.
        /// </summary>
        public static void Initialize()
        {
            Game         gameInstance = InitializeHelper.GetGameClass();
            RenderTarget renderTarget;

            try
            {
                renderTarget = RenderTarget.Default;
            }
            catch (InvalidOperationException)
            {
                renderTarget = RenderTarget.Create();
            }

            var sglInitializer = new Configurator(gameInstance, renderTarget);

            Initialize(sglInitializer);
        }
InitializeHelper