mirror of
https://github.com/DCFApixels/DragonECS-AutoInjections.git
synced 2025-09-17 20:34:34 +08:00
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using DCFApixels.DragonECS.AutoInjections.Internal;
|
|
using System;
|
|
using System.Reflection;
|
|
|
|
namespace DCFApixels.DragonECS
|
|
{
|
|
public static class ProcessRunnerBinder
|
|
{
|
|
private static MethodInfo _declareRunnerMethod = typeof(EcsPipeline).GetMethod(nameof(EcsPipeline.DeclareRunner));
|
|
public static T GetRunnerAuto<T>(this EcsPipeline self) where T : IEcsProcess
|
|
{
|
|
if(self.TryGetRunner(out T process))
|
|
{
|
|
return process;
|
|
}
|
|
Type type = typeof(T);
|
|
if (type.TryGetCustomAttribute(out BindWithRunnerAttribute atr))
|
|
{
|
|
Type runnerType = atr.runnerType;
|
|
if (type.IsGenericType)
|
|
{
|
|
if(runnerType.IsGenericType == false ||
|
|
runnerType.IsGenericTypeDefinition == false)
|
|
{
|
|
Throw.UndefinedException();
|
|
}
|
|
|
|
Type[] genericArguments = type.GetGenericArguments();
|
|
runnerType = runnerType.MakeGenericType(genericArguments);
|
|
}
|
|
return (T)_declareRunnerMethod.MakeGenericMethod(runnerType).Invoke(self, null);
|
|
}
|
|
Throw.UndefinedException();
|
|
return default;
|
|
}
|
|
}
|
|
}
|