Inheritance: System.Attribute
Example #1
0
        public void Load(Assembly assembly)
        {
            this.allEvents = new Dictionary <EventType, List <object> >();

            ServerType serverType = World.Instance.Options.ServerType;

            Type[] types = assembly.GetTypes();
            foreach (Type t in types)
            {
                object[] attrs = t.GetCustomAttributes(typeof(AttributeType), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                AEventAttribute aEventAttribute = (AEventAttribute)attrs[0];
                if (!aEventAttribute.Contains(serverType))
                {
                    continue;
                }

                object obj = Activator.CreateInstance(t);
                if (obj == null)
                {
                    throw new Exception($"event not inherit IEvent or IEventAsync interface: {obj.GetType().FullName}");
                }
                if (!this.allEvents.ContainsKey(aEventAttribute.Type))
                {
                    this.allEvents.Add(aEventAttribute.Type, new List <object>());
                }
                this.allEvents[aEventAttribute.Type].Add(obj);
            }
        }
Example #2
0
        public void Load(Assembly assembly)
        {
            this.events = new Dictionary <int, List <IEvent> >();

            var types = assembly.GetTypes();

            foreach (var t in types)
            {
                object[] attrs = t.GetCustomAttributes(typeof(AttributeType), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj    = Activator.CreateInstance(t);
                IEvent iEvent = obj as IEvent;
                if (iEvent == null)
                {
                    throw new Exception(string.Format("event not inherit IEvent interface: {0}",
                                                      obj.GetType().FullName));
                }

                AEventAttribute iEventAttribute = (AEventAttribute)attrs[0];

                if (!this.events.ContainsKey(iEventAttribute.Type))
                {
                    this.events.Add(iEventAttribute.Type, new List <IEvent>());
                }
                this.events[iEventAttribute.Type].Add(iEvent);
            }
        }