Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Callee
- {
- public void RegularCall(int command, parameters)
- {
- switch (command)
- {
- case 1: // Comand #1
- // Check if the permissions allow this command to be called.
- // Check if it should be outsourced to the ThreadPool and
- // call it accordingly. +Other Checks.
- // Finally execute command #1.
- break;
- case 2: // Comand #2
- // Check if the permissions allow that command to be called.
- // Check if it should be outsourced to the ThreadPool and
- // call it accordingly. +Other Checks.
- // Finally execute command #2.
- break;
- // Many more cases with various combinations of permissions and
- // Other flags.
- }
- }
- }
- static Dictionary<int, Callee> callees = new Dictionary<int, Callee>();
- static void CallMethod(int elementId, int commandId, parameters)
- {
- callees[elementId].RegularCall(commandId, parameters);
- }
- class Callee
- {
- [Command(1)]
- [Permissions(0b00111000)]
- [UseThreadPool]
- public void SpeakingNameForCommand1(parameters)
- {
- // Code for command #1.
- }
- [Command(2)]
- [Permissions(0b00101011)]
- public void SpeakingNameForCommand2(parameters)
- {
- // Code for command #2.
- }
- // Again, many more commands.
- }
- static Dictionary<int, CommandInfo> commands = new Dictionary<int, CommandInfo>();
- static void CallMethod(int elementId, int commandId)
- {
- CommandInfo ci = commands[commandId];
- if (ci.Permissions != EVERYTHING_OK)
- throw ...;
- if (ci.UseThreadPool)
- ThreadPool.Queue...(delegate { ci.MethodInfover.Invoke(callees[elementId], params); });
- else
- ci.MethodInfo.Invoke(callees[elementId], params);
- }
Add Comment
Please, Sign In to add comment