Exemple #1
0
 private Type GetCommandType(string name)
 {
     return(AssemblyFinder.GetCurrentAssemblyWithDependencies()
            .SelectMany(x => x.GetTypes()
                        .Where(
                            t => t.GetTypeInfo().GetCustomAttribute <CommandHandlerAttribute>() != null))
            .FirstOrDefault(x => x.GetTypeInfo()
                            .GetCustomAttribute <CommandHandlerAttribute>().CommandName == name));
 }
Exemple #2
0
        public static void RegisterConsoleCommands(this ContainerBuilder containerBuilder)
        {
            Type[] commandsToRegister = AssemblyFinder
                                        .GetCurrentAssemblyWithDependencies()
                                        .SelectMany(x => x.GetTypes()
                                                    .Where(t => t.GetTypeInfo()
                                                           .GetCustomAttribute <CommandHandlerAttribute>() != null))
                                        .ToArray();

            foreach (var command in commandsToRegister)
            {
                var commandAttribute = command.GetTypeInfo().GetCustomAttribute <CommandHandlerAttribute>();
                containerBuilder.RegisterType(command).Named(commandAttribute.CommandName, command);
            }
        }
Exemple #3
0
        private string GetQualifiedCommandName(string commandName)
        {
            var commandType = AssemblyFinder
                              .GetCurrentAssemblyWithDependencies()
                              .SelectMany(x => x.GetTypes()
                                          .Where(t => t.GetTypeInfo().GetCustomAttribute <CommandAttribute>() != null))
                              .FirstOrDefault(x =>
                                              x.GetTypeInfo().GetCustomAttribute <CommandAttribute>().Name == commandName ||
                                              x.GetTypeInfo().GetCustomAttribute <CommandAttribute>().Alias == commandName
                                              );

            string retName = string.Empty;

            if (commandType != null)
            {
                retName = commandType.GetTypeInfo().GetCustomAttribute <CommandAttribute>().Name;
            }

            return(retName);
        }