Exemplo n.º 1
0
        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,
                });
            }
        }
Exemplo n.º 2
0
 public IEnumerator <SwitchSection> GetEnumerator()
 {
     return(SectionsInternal.GetEnumerator());
 }