internal void Register() { var type = GetType(); foreach (var member in type.GetMembers()) { foreach (object attribute in member.GetCustomAttributes(true)) { if (attribute is OnCommandAttribute) { if (member is MethodInfo) { Commands.Add(new MethodCommandTrigger <T>(this, attribute as OnCommandAttribute, member as MethodInfo)); } else if (member is PropertyInfo) { Commands.Add(new PropertyCommandTrigger <T>(this, attribute as OnCommandAttribute, member as PropertyInfo)); } } else if (attribute is OnUserJoinAttribute) { if (member is MethodInfo) { UserJoins.Add(new UserJoinTrigger <T>(this, member as MethodInfo)); } } else if (attribute is OnUserLeaveAttribute) { if (member is MethodInfo) { UserLeaves.Add(new UserLeaveTrigger <T>(this, member as MethodInfo)); } } else if (attribute is PreCommandAttribute) { if (member is MethodInfo) { PreCommands.Add(new MethodPreCommandTrigger <T>(this, attribute as PreCommandAttribute, member as MethodInfo)); } else if (member is PropertyInfo) { PreCommands.Add(new PropertyPreCommandTrigger <T>(this, attribute as PreCommandAttribute, member as PropertyInfo)); } } } } }
public void Execute(object parameter) { if (_action == null) { return; } //Pre commands if (PreCommands.Count > 0) { foreach (var preCommand in PreCommands) { if (_ignorePreCommands == null || !_ignorePreCommands.Where((i, index) => index == PreCommands.IndexOf(preCommand)).Any()) { preCommand(); } } } //Actual Command _action(); //Post commands if (PostCommands.Count > 0) { foreach (var postCommand in PostCommands) { if (_ignorePostCommands == null || !_ignorePostCommands.Where((i, index) => index == PostCommands.IndexOf(postCommand)).Any()) { postCommand(); } } } }