예제 #1
0
파일: Multiply.cs 프로젝트: lzcd/Crass
        public void Operate()
        {
            var expressionParent = (Expression)Parent;
            var operatorIndex = expressionParent.Children.IndexOf(this);
            var a = expressionParent.Children[operatorIndex - 1];
            var b = expressionParent.Children[operatorIndex + 1];

            expressionParent.Children.RemoveRange(operatorIndex - 1, 3);

            if (a is Units && b is Units)
            {
                var aUnits = (Units)a;
                var bUnits = (Units)b;
                var result = new Units(expressionParent) { Amount = (aUnits.Amount * bUnits.Amount), Unit = aUnits.Unit };
                expressionParent.Children.Insert(operatorIndex - 1, result);
            }
        }
예제 #2
0
파일: Units.cs 프로젝트: lzcd/Crass
 internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Units units)
 {
     int firstDigit;
     if (!int.TryParse(remainingWords.Peek().Text.Substring(0,1), out firstDigit))
     {
         units = null;
         return false;
     }
     var text = remainingWords.Dequeue().Text;
     var index = 0;
     while (index < text.Length &&
         text.Substring(index, 1).IndexOfAny(numericCharacters) >= 0)
     {
         index++;
     }
     var amount = Decimal.Parse(text.Substring(0, index));
     var unit = text.Substring(index);
     units = new Units(parent) { Amount = amount, Unit = unit };
     return true;
 }