void CompositeEvent(Expression <Func <Event> > propertyExpression, CompositeEventStatusAccessor <TInstance> accessor, CompositeEventOptions options, Event[] events) { if (events == null) { throw new ArgumentNullException(nameof(events)); } if (events.Length > 31) { throw new ArgumentException("No more than 31 events can be combined into a single event"); } if (events.Length == 0) { throw new ArgumentException("At least one event must be specified for a composite event"); } if (events.Any(x => x == null)) { throw new ArgumentException("One or more events specified has not yet been initialized"); } PropertyInfo eventProperty = propertyExpression.GetPropertyInfo(); string name = eventProperty.Name; var @event = new TriggerEvent(name); eventProperty.SetValue(this, @event); _eventCache[name] = new StateMachineEvent <TInstance>(@event, false); var complete = new CompositeEventStatus(Enumerable.Range(0, events.Length) .Aggregate(0, (current, x) => current | (1 << x))); for (int i = 0; i < events.Length; i++) { int flag = 1 << i; var activity = new CompositeEventActivity <TInstance>(accessor, flag, complete, @event); Func <State <TInstance>, bool> filter = x => options.HasFlag(CompositeEventOptions.IncludeInitial) || !Equals(x, Initial); foreach (var state in _stateCache.Values.Where(filter)) { During(state, When(events[i]) .Execute(x => activity)); } } }