コード例 #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;
 }