using System; using System.Collections.Generic; using System.Reflection; namespace Encompass { class UberRenderer : Renderer { private Entity _entity; private IEnumerable _componentTypes; public UberRenderer(Entity entity, IEnumerable componentTypes) { _entity = entity; _componentTypes = componentTypes; } public void Render() { foreach (var type in _componentTypes) { CallGenericMethod(type, "ReadEntities", null); CallGenericMethod(type, "ReadEntity", null); CallGenericMethod(type, "ReadComponent", null); CallGenericMethod(type, "ReadComponentIncludingEntity", null); CallGenericMethod(type, "ReadComponents", null); CallGenericMethod(type, "ReadComponentsIncludingEntity", 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); } } }