Update GameFrameworkEntry.cs

This commit is contained in:
ALEXTANG
2023-04-19 14:20:05 +08:00
parent 3c908a7955
commit 611f1ffab9

View File

@@ -47,22 +47,18 @@ namespace TEngine
/// <remarks>如果要获取的游戏框架模块不存在,则自动创建该游戏框架模块。</remarks>
public static T GetModule<T>() where T : class
{
Type interfaceType = typeof(T);
if (!interfaceType.IsInterface)
Type module = typeof(T);
if (module.FullName != null && !module.FullName.StartsWith("TEngine.", StringComparison.Ordinal))
{
throw new GameFrameworkException(Utility.Text.Format("You must get module by interface, but '{0}' is not.", interfaceType.FullName));
throw new GameFrameworkException(Utility.Text.Format("You must get a Game Framework module, but '{0}' is not.", module.FullName));
}
if (!interfaceType.FullName.StartsWith("TEngine.", StringComparison.Ordinal))
{
throw new GameFrameworkException(Utility.Text.Format("You must get a Game Framework module, but '{0}' is not.", interfaceType.FullName));
}
string moduleName = Utility.Text.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name.Substring(1));
string moduleName = Utility.Text.Format("{0}.{1}", module.Namespace, module.Name.Substring(1));
Type moduleType = Type.GetType(moduleName);
if (moduleType == null)
{
moduleName = Utility.Text.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name);
moduleName = Utility.Text.Format("{0}.{1}", module.Namespace, module.Name);
moduleType = Type.GetType(moduleName);
if (moduleType == null)
{