/// <summary> /// Adds a command to the model map. /// </summary> /// <param name="command">The command.</param> /// <returns>The ModelMap.</returns> public ModelMap AddCommand(ModelCommand command) { var commandName = command.Name; if (commandName.EndsWith("Async")) { var type = command.Method.ReturnParameter.ParameterType; if (type == typeof(Task) || type.IsSubclassOf(typeof(Task))) { commandName = commandName.Substring(0, commandName.Length - 5); } } this.Commands.Add(commandName, command); return(this); }
/// <summary> /// Populates the actions. /// </summary> /// <param name="model">The model.</param> /// <returns>A Enumerable of ModelCommands.</returns> private static IEnumerable <ModelCommand> PopulateCommands(object model) { var runtimeMethods = model.GetType().GetRuntimeMethods(); var methodInfos = GetMappableMethods(runtimeMethods); foreach (var method in methodInfos) { var action = new ModelCommand(method.Name, method, model) { DisplayName = method.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName ?? CreateFriendlyName(method.Name), Description = method.GetCustomAttribute <DescriptionAttribute>()?.Description }; yield return(action); } }