public SwitchResult Execute(TMatch matchExpression) { SwitchSection matched; if (matchExpression == null) { matched = SectionsInternal.FirstOrDefault(s => s.Value == null); } else { matched = SectionsInternal.FirstOrDefault(s => matchExpression.Equals(s.Value)); } if (matched is null) { if (DefaultInternal != null) { DefaultInternal.Action?.Invoke(); return(new SwitchResult() { Matched = true, Result = DefaultInternal.Result, }); } else { return(new SwitchResult() { Matched = false, }); } } else { matched.Action?.Invoke(); return(new SwitchResult() { Matched = true, Result = matched.Result, }); } }
public IEnumerator <SwitchSection> GetEnumerator() { return(SectionsInternal.GetEnumerator()); }