提交 89c73348 编写于 作者: T tanghai

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

上级 f2813f94
......@@ -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;
}
}
}
\ No newline at end of file
......@@ -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);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册