/// <summary> /// It initializes a new instance of the class. /// </summary> /// <param name="fieldNumber"> /// It's the number of the field this formatter formats/parse. /// </param> /// <param name="expression"> /// It's the expression to evaluate, based in the result <paramref name="trueFormatter"/> /// or <paramref name="falseFormatter" /> are used in the formatting/parsing of a message. /// </param> /// <param name="trueFormatter"> /// It's the formatter to be used when <paramref name="expression"/> is true. /// </param> /// <param name="falseFormatter"> /// It's the formatter to be used when <paramref name="expression"/> is false. /// </param> /// <param name="description"> /// It's the description of the field formatter. /// </param> public ConditionalFieldFormatter(int fieldNumber, string expression, FieldFormatter trueFormatter, FieldFormatter falseFormatter, string description) : base(fieldNumber, description) { if (trueFormatter == null) { throw new ArgumentNullException("trueFormatter"); } if (falseFormatter == null) { throw new ArgumentNullException("falseFormatter"); } _expression = expression; _trueFormatter = trueFormatter; _falseFormatter = falseFormatter; Tokenizer tokenizer = new Tokenizer( new StringReader(_expression)); SemanticParser sp = new SemanticParser(); object result = null; try { result = sp.yyparse(tokenizer); } catch (Exception ex) { throw new ExpressionCompileException(ex.Message, tokenizer.LastParsedTokenIndex); } _compiledExpression = result as IBooleanExpression; if (_compiledExpression == null) { throw new ApplicationException("Unknown result from expression."); } _evaluator = this; }
/// <summary> /// It initializes a new instance of the class. /// </summary> /// <param name="fieldNumber"> /// It's the number of the field this formatter formats/parse. /// </param> /// <param name="evaluator"> /// It's the evaluator which decides which field formatter must be used between /// <paramref name="trueFormatter"/> and <paramref name="falseFormatter" />, /// in the formatting/parsing of a message. /// </param> /// <param name="trueFormatter"> /// It's the formatter to be used when <paramref name="expression"/> is true. /// </param> /// <param name="falseFormatter"> /// It's the formatter to be used when <paramref name="expression"/> is false. /// </param> /// <param name="description"> /// It's the description of the field formatter. /// </param> public ConditionalFieldFormatter(int fieldNumber, IConditionalFieldEvaluator evaluator, FieldFormatter trueFormatter, FieldFormatter falseFormatter, string description) : base(fieldNumber, description) { if (evaluator == null) { throw new ArgumentNullException("evaluator"); } if (trueFormatter == null) { throw new ArgumentNullException("trueFormatter"); } if (falseFormatter == null) { throw new ArgumentNullException("falseFormatter"); } _evaluator = evaluator; _trueFormatter = trueFormatter; _falseFormatter = falseFormatter; }
/// <summary> /// It initializes a new instance of the class. /// </summary> /// <param name="fieldNumber"> /// It's the number of the field this formatter formats/parse. /// </param> /// <param name="evaluator"> /// It's the evaluator which decides which field formatter must be used between /// <paramref name="trueFormatter"/> and <paramref name="falseFormatter" />, /// in the formatting/parsing of a message. /// </param> /// <param name="trueFormatter"> /// It's the formatter to be used when <paramref name="expression"/> is true. /// </param> /// <param name="falseFormatter"> /// It's the formatter to be used when <paramref name="expression"/> is false. /// </param> public ConditionalFieldFormatter(int fieldNumber, IConditionalFieldEvaluator evaluator, FieldFormatter trueFormatter, FieldFormatter falseFormatter) : this(fieldNumber, evaluator, trueFormatter, falseFormatter, string.Empty) { }