trying PrepareMethod instead of Invoke
continuous-integration/drone/push Build is passing Details

pull/3/head
Evan Hemsley 2020-03-22 14:04:09 -07:00
parent 5a536e6123
commit 0d969322ad
1 changed files with 9 additions and 5 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Encompass
{
@ -59,8 +60,7 @@ namespace Encompass
CallGenericMethod(type, "SendMessage", 2, new object[] { Activator.CreateInstance(type), 1 });
CallGenericMethod(type, "ReadMessage", null);
// can't reflect on methods that return a span...
//CallGenericMethod(type, "ReadMessages", null);
CallGenericMethod(type, "ReadMessages", null);
CallGenericMethod(type, "SomeMessage", null);
if (typeof(IHasEntity).IsAssignableFrom(type))
{
@ -71,25 +71,29 @@ namespace Encompass
}
}
// trying to use PrepareMethod because we can't reflect invoke methods that return a span...
private void CallGenericMethod(Type type, string methodName, object[] parameters)
{
var readComponentMethod = typeof(Engine).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
genericReadComponentMethod.Invoke(this, parameters);
//genericReadComponentMethod.Invoke(this, parameters);
RuntimeHelpers.PrepareMethod(genericReadComponentMethod.MethodHandle);
}
private void CallGenericMethod(Type type, string methodName, Type[] types, object[] parameters)
{
var readComponentMethod = typeof(Engine).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance, null, types, null);
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
genericReadComponentMethod.Invoke(this, parameters);
//genericReadComponentMethod.Invoke(this, parameters);
RuntimeHelpers.PrepareMethod(genericReadComponentMethod.MethodHandle);
}
private void CallGenericMethod(Type type, string methodName, int argumentNum, object[] parameters)
{
var method = typeof(Engine).GetRuntimeMethods().Where(m => m.Name == methodName && m.GetParameters().Length == argumentNum).First();
var genericMethod = method.MakeGenericMethod(type);
genericMethod.Invoke(this, parameters);
//genericMethod.Invoke(this, parameters);
RuntimeHelpers.PrepareMethod(genericMethod.MethodHandle);
}
}
}