public bool AppliesTo(MarkupElement originalElement, MarkupElement pipeElement) { //get the index of the element int index = pipeElement.Index; //odd/even? if (p_Odd) { return index % 2 != 0; } if (p_Even) { return index % 2 == 0; } //substitute for n? if (!p_HasNSubstitute) { //index has to match the result of the calculation return index == p_ExpressionResult; } //use the n substitute as an accumulator and //see if the result of the expression //matches the elements index. ArithmeticSubstitute n = new ArithmeticSubstitute( new ArithmeticOperand(0), 'n'); LinkedList<ArithmeticSubstitute> subs = new LinkedList<ArithmeticSubstitute>(); subs.AddLast(n); for (int c = 0; c <= index; c++) { n.Operand.setValue(c, false, true); ArithmeticNumeric res = p_Expression.Calculate(subs); if (res == index) { return true; } } //no match return false; }
private bool substituteExist(char name, LinkedList<ArithmeticSubstitute> subs, out ArithmeticSubstitute found) { found = default(ArithmeticSubstitute); //look for the name IEnumerator<ArithmeticSubstitute> e = subs.GetEnumerator(); while (e.MoveNext()) { ArithmeticSubstitute current = e.Current; if (current.Name == name) { e.Dispose(); found = current; return true; } } //not found e.Dispose(); return false; }