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

InitializeChannelMode() private method

private InitializeChannelMode ( Assembly asm ) : void
asm System.Reflection.Assembly
return void
        private void InitializeChannelMode(Assembly asm)
        {
            Dictionary<Modes, ReceivedChannelModeEventHandler> addChannelModeHandlers = new Dictionary<Modes, ReceivedChannelModeEventHandler>();
            Dictionary<Modes, ReceivedChannelModeEventHandler> removeChannelModeHandlers = new Dictionary<Modes, ReceivedChannelModeEventHandler>();
            Dictionary<Modes, ChannelModeAttribute> channelModeAttrs = new Dictionary<Modes, ChannelModeAttribute>();

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

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

                    IChannelMode command = (IChannelMode)t.GetConstructor(Type.EmptyTypes).Invoke(new object[0]);
                    addChannelModeHandlers.Add(attrs[0].Mode, command.AddHandler);
                    removeChannelModeHandlers.Add(attrs[0].Mode, command.RemoveHandler);
                    channelModeAttrs.Add(attrs[0].Mode, attrs[0]);
                }
                catch
                {
                    Console.WriteLine("Error loading channel mode handler {0}.", t);
                }
            }

            AddChannelModeHandlers = addChannelModeHandlers;
            RemoveChannelModeHandlers = removeChannelModeHandlers;
            ChannelModeAttrs = channelModeAttrs;
        }