// called to create a non-derived event for simple things; // but keep other classes limited to calling specific factory // methods protected static EventOfHurt CreateGeneric( EEventType evt, ESubsystem src, ESubsystem dest = ESubsystem.Dispatcher, Tuple <EventOfHurt, DateTime>[] reasons = null ) { EventOfHurt RetVal; if (dest == null) { dest = ESubsystem.Dispatcher; } List <Tuple <EventOfHurt, DateTime> > ReasonList = new List <Tuple <EventOfHurt, DateTime> >(); if (reasons != null) { ReasonList.AddRange(reasons); } // the initializer after the constructor allows for a // lot more flexibility than e.g., optional params RetVal = new EventOfHurt(evt, src) { myEventReferences = ReasonList }; return(RetVal); }
// some of the specific methods can just return a generic // non-derived event public static EventOfHurt CreateTickerTimerEvent( EEventType evt, ESubsystem dest ) { ESubsystem src = ESubsystem.TickerTimer; return(CreateGeneric(evt, src, dest, null)); }
// some may return actual derived classes public static EventOfHurt CreatePlayerActionEvent( EEventType evt, ESubsystem dest, Tuple <EventOfHurt, DateTime>[] reasons ) { PlayerEvent PE = new PlayerActionEvent(42); return(PE); }
// we'll be using factor methods to create events // so keep constructors private; no default constructor private EventOfHurt( EEventType evt, ESubsystem src, ESubsystem dest = ESubsystem.Dispatcher ) { EventType = evt; SourceSubsystem = src; DestSubsystem = dest; EventId = Guid.NewGuid(); Timestamp = DateTime.UtcNow; }
public SubsystemParser(ushort subsystem) { subsys = (ESubsystem)subsystem; }