using System; using System.Collections.Generic; using System.Reflection; namespace Encompass { class UberRenderer : Renderer { private readonly IEnumerable _componentTypes; private Entity _entity; public UberRenderer(IEnumerable componentTypes) { _componentTypes = componentTypes; } public void SetEntity(Entity entity) { _entity = entity; } // can't reflect invoke on Span returns... public void Render() { foreach (var type in _componentTypes) { // CallGenericMethod(type, "ReadEntities", null); CallGenericMethod(type, "ReadEntity", null); // CallGenericMethod(type, "ReadComponents", null); CallGenericMethod(type, "ReadComponent", null); CallGenericMethod(type, "GetComponent", new object[] { _entity }); CallGenericMethod(type, "HasComponent", new object[] { _entity }); CallGenericMethod(type, "SomeComponent", null); } } private void CallGenericMethod(Type type, string methodName, object[] parameters) { var readComponentMethod = typeof(Renderer).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance); var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type); genericReadComponentMethod.Invoke(this, parameters); } } }