/// <summary> /// Registers new command handler in the factory. /// </summary> /// <param name="groupID">Command group GUID.</param> /// <param name="commandID">Command identifier.</param> /// <param name="createMethod">Create command handler method delegate.</param> public void RegisterCommandHandler(Guid groupID, int commandID, CreateCommandMethod createMethod) { if (createMethod == null) { throw new ArgumentNullException("createMethod"); } // Create key structure CommandIDKey key = new CommandIDKey(groupID, commandID); // Check, if handler already registered if (commandHandlersDictionary.ContainsKey(key)) { return; } commandHandlersDictionary.Add(key, createMethod); }
/// <summary> /// Returns instance of the command handler. /// </summary> /// <param name="groupID">Command group GUID.</param> /// <param name="commandID">Command identifier.</param> /// <returns>Returns instance of the command handler.</returns> public ICommand CreateCommandHandler(Guid groupID, int commandID) { // Creating key structure CommandIDKey key = new CommandIDKey(groupID, commandID); // Check handler registration if (!commandHandlersDictionary.ContainsKey(key)) { return(null); } // Get create method and create instance CreateCommandMethod createMethod = commandHandlersDictionary[key]; if (createMethod == null) { return(null); } return(createMethod.Invoke()); }
/// <summary> /// Registers new command handler in the factory. /// </summary> /// <param name="groupID">Command group GUID.</param> /// <param name="commandID">Command identifier.</param> /// <param name="createMethod">Create command handler method delegate.</param> public void RegisterCommandHandler(Guid groupID, int commandID, CreateCommandMethod createMethod) { if (createMethod == null) throw new ArgumentNullException("createMethod"); // Create key structure CommandIDKey key = new CommandIDKey(groupID, commandID); // Check, if handler already registered if (commandHandlersDictionary.ContainsKey(key)) return; commandHandlersDictionary.Add(key, createMethod); }
/// <summary> /// Returns instance of the command handler. /// </summary> /// <param name="groupID">Command group GUID.</param> /// <param name="commandID">Command identifier.</param> /// <returns>Returns instance of the command handler.</returns> public ICommand CreateCommandHandler(Guid groupID, int commandID) { // Creating key structure CommandIDKey key = new CommandIDKey(groupID, commandID); // Check handler registration if( !commandHandlersDictionary.ContainsKey(key)) return null; // Get create method and create instance CreateCommandMethod createMethod = commandHandlersDictionary[key]; if (createMethod == null) return null; return createMethod.Invoke(); }