Explorar el Código

事件分发不设顺序,因为订阅的事件可能在不同的程序集,无法设置执行顺序

tanghai hace 11 años
padre
commit
89c7334815

+ 1 - 3
CSharp/Platform/Common/Event/AEventAttribute.cs

@@ -6,12 +6,10 @@ namespace Common.Event
     public abstract class AEventAttribute : Attribute
     {
         public int Type { get; private set; }
-        public int Order { get; private set; }
 
-        protected AEventAttribute(int type, int order)
+        protected AEventAttribute(int type)
         {
             this.Type = type;
-            this.Order = order;
         }
     }
 }

+ 6 - 6
CSharp/Platform/Common/Event/EventTrigger.cs

@@ -5,11 +5,11 @@ namespace Common.Event
 {
     public class EventTrigger<T> where T : AEventAttribute
     {
-        private readonly Dictionary<int, SortedDictionary<int, IEvent>> events;
+        private readonly Dictionary<int, List<IEvent>> events;
 
         public EventTrigger()
         {
-            this.events = new Dictionary<int, SortedDictionary<int, IEvent>>();
+            this.events = new Dictionary<int, List<IEvent>>();
 
             Type type = typeof (T);
             var types = type.Assembly.GetTypes();
@@ -32,15 +32,15 @@ namespace Common.Event
 
                 if (!this.events.ContainsKey(iEventAttribute.Type))
                 {
-                    this.events.Add(iEventAttribute.Type, new SortedDictionary<int, IEvent>());
+                    this.events.Add(iEventAttribute.Type, new List<IEvent>());
                 }
-                this.events[iEventAttribute.Type].Add(iEventAttribute.Order, iEvent);
+                this.events[iEventAttribute.Type].Add(iEvent);
             }
         }
 
         public void Trigger(int type, Env env)
         {
-            SortedDictionary<int, IEvent> iEventDict = null;
+            List<IEvent> iEventDict = null;
             if (!this.events.TryGetValue(type, out iEventDict))
             {
                 return;
@@ -48,7 +48,7 @@ namespace Common.Event
 
             foreach (var iEvent in iEventDict)
             {
-                iEvent.Value.Trigger(env);
+                iEvent.Trigger(env);
             }
         }
     }