//again shortening common actions Timer registerBehavior(ITimerBehavior behav) { behavior = behav; behaviorBase = (TimerBehaviorBase)behavior; behaviorBase.timer = this; return(this); }
Timer SetBehavior <T>() where T : TimerBehaviorBase, new() { Type t = typeof(T); ITimerBehavior behav = null; if (TimerManager.behaviors.ContainsKey(t)) { List <ITimerBehavior> list = TimerManager.behaviors[t]; if (list.Count > 0) { behav = list[0]; list.Remove(behav); } } if (behav == null) { behav = (ITimerBehavior) new T(); } registerBehavior(behav); return(this); }