} // LoanStat private void TryToConstruct(string formulaPattern) { if (string.IsNullOrWhiteSpace(formulaPattern)) { Constructed = null; return; } // if var re = new Regex("^(Max|Min)Count(And|Or)(Max|Min)Amount$"); Match match = re.Match(formulaPattern.Trim()); if (!match.Success) { Constructed = null; return; } // if IFittable leftTerm = (match.Groups[1].Value == "Max") ? (IFittable) new MaxCount() : (IFittable) new MinCount(); IFittable rightTerm = (match.Groups[3].Value == "Max") ? (IFittable) new MaxAmount() : (IFittable) new MinAmount(); Type opType = (match.Groups[2].Value == "And") ? typeof(And) : typeof(Or); Constructed = new CountAmount(opType, leftTerm, rightTerm); } // TryToConstruct
public CountAmount(Type opType, IFittable leftTerm, IFittable rightTerm) { this.leftTerm = leftTerm; this.rightTerm = rightTerm; if (typeof(ABinaryBoolOperator).IsAssignableFrom(opType)) { this.op = (ABinaryBoolOperator)Activator.CreateInstance(opType, leftTerm, rightTerm); } else { this.op = null; } } // constructor