public void Super(string behavior) { if (next == null) { throw new InvalidOperationException($"Super behavior can only be specified while behavior configuration is in progress. " + $"Current: {Current}, Offending: {behavior}"); } if (next.Includes(behavior)) { throw new InvalidOperationException("Detected cyclic declaration of super behaviors. " + $"'{behavior}' is already within super chain of {next.Name}"); } var existent = current.FindSuper(behavior); if (existent != null) { next.Super(existent); return; } var prev = next; next = new CustomBehavior(behavior); prev.Super(next); var action = RegisteredAction(behavior); action(actor); next = prev; }
bool Includes(CustomBehavior behavior) => this == behavior || (sub?.Includes(behavior) ?? false);