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())); }
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); }
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; } }
void Start() { RightHand = new NoItem(); LeftHand = new NoItem(); }