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 override void Render(double dt, double alpha) { foreach (var type in _componentTypes) { CallGenericWrappedMethod(type, "CallAllComponentMethods", null); } } protected void CallAllComponentMethods() where TComponent : struct { ReadEntity(); ReadEntities(); ReadComponent(); ReadComponents(); GetComponent(_entity); HasComponent(_entity); SomeComponent(); } private void CallGenericWrappedMethod(Type type, string methodName, object[] parameters) { var readComponentMethod = typeof(UberRenderer).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance); var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type); genericReadComponentMethod.Invoke(this, parameters); } } }