コード例 #1
0
        private IEquationSet OperateSubString(string substring)
        {
            substring = substring.Trim(_thousandSeparator, ' ') + '\0';

            var     eqSubset      = new List <IEqItem>();
            int     position      = 0;
            IEqItem processedItem = null;
            var     itemFactory   = new EquationItemFactory();

            do
            {
                var sign = substring[position];
                if (itemFactory.CanOperate(processedItem, sign))
                {
                    if (processedItem != null)
                    {
                        itemFactory.GetProcessedItemValue(processedItem,
                                                          substring.Substring(processedItem.Position, position - processedItem.Position));
                        eqSubset.Add(processedItem);
                    }

                    processedItem = itemFactory.GetOperation(sign, position);
                }

                position++;
            } while (substring.Length > position);

            return(new EquationSet(eqSubset.ToArray()));
        }
コード例 #2
0
        public bool CanOperate(IEqItem processedItem, char sign)
        {
            if (char.IsDigit(sign) && !((processedItem is Variable) || (processedItem is Number)) ||
                Operations.Contains(sign) || sign == '\0')
            {
                return(true);
            }

            return(false);
        }
コード例 #3
0
        public void GetProcessedItemValue(IEqItem processedItem, string value)
        {
            switch (processedItem)
            {
            case var _ when processedItem is Number number:
                if (double.TryParse(value, out var result))
                {
                    number.SetValue(result);
                }
                break;

            case var _ when processedItem is Variable variable:
                variable.SetName(value);
                break;
            }
        }
コード例 #4
0
 void Start()
 {
     RightHand = new NoItem();
     LeftHand  = new NoItem();
 }