Aselia.Common.Hotswap.DomainManager.InitializeUserCommand C# (CSharp) Method

InitializeUserCommand() private method

private InitializeUserCommand ( Assembly asm ) : void
asm System.Reflection.Assembly
return void
        private void InitializeUserCommand(Assembly asm)
        {
            Dictionary<string, ReceivedCommandEventHandler> userCommandHandlers = new Dictionary<string, ReceivedCommandEventHandler>();
            Dictionary<string, CommandAttribute> userCommandAttrs = new Dictionary<string, CommandAttribute>();

            IEnumerable<Type> types = from x in asm.GetTypes()
                                      where x.GetInterfaces().Contains(typeof(ICommand))
                                      select x;

            foreach (Type t in types)
            {
                try
                {
                    CommandAttribute[] attrs = t.GetCustomAttributes(typeof(CommandAttribute), false).Cast<CommandAttribute>().ToArray();
                    if (attrs.Length < 1)
                    {
                        continue;
                    }

                    ICommand command = (ICommand)t.GetConstructor(Type.EmptyTypes).Invoke(new object[0]);
                    for (int i = 0; i < attrs[0].Commands.Length; i++)
                    {
                        userCommandHandlers[attrs[0].Commands[i]] = command.Handler;
                        userCommandAttrs[attrs[0].Commands[i]] = attrs[0];
                    }
                }
                catch
                {
                    Console.WriteLine("Error loading command handler {0}.", t);
                }
            }

            UserCommandHandlers = userCommandHandlers;
            UserCommandAttrs = userCommandAttrs;
        }