private void ProcessOperations() { foreach (MethodInfo method in (typeof(CPU)).GetMethods()) { foreach (var attribute in method.GetCustomAttributes(typeof(CPUFunction), true)) { CPUFunction function = attribute as CPUFunction; Delegate methodDelegate; try { switch (method.GetParameters().Length) { case 0: methodDelegate = Delegate.CreateDelegate(typeof(CPUCallbackNoargs), this, method); break; case 1: methodDelegate = Delegate.CreateDelegate(typeof(CPUCallback1args), this, method); break; case 2: methodDelegate = Delegate.CreateDelegate(typeof(CPUCallback2args), this, method); break; case 3: methodDelegate = Delegate.CreateDelegate(typeof(CPUCallback3args), this, method); break; case 4: methodDelegate = Delegate.CreateDelegate(typeof(CPUCallback4args), this, method); break; default: throw new Exception("Method signature not supported"); } } catch (Exception) { throw new Exception("Method signature not supported"); } for (int i = 0; i < function.Count; i++) { disasm.AddOperation((uint)(function.OpCode + i), methodDelegate, method.GetParameters().Length); } } } }