diff --git a/encompass-cs/UberEngine.cs b/encompass-cs/UberEngine.cs index 0003928..48d64c4 100644 --- a/encompass-cs/UberEngine.cs +++ b/encompass-cs/UberEngine.cs @@ -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); } } }