public static Checker Create(string name, CompareOperator op = CompareOperator.Equal, string val = null) { Checker checker = null; name = name.ToLower(); if (!_derivedTypes.ContainsKey(name)) { throw new FormatException($"未知的变量名'{name}'"); } Type type = _derivedTypes[name]; if (_validOperators.ContainsKey(type) && !_validOperators[type]?.Contains(op) == true) { throw new FormatException($"不支持的运算符'{op.GetDesc()}'"); } checker = Activator.CreateInstance(type) as Checker; checker._Operator = op; checker._Val = val; var errmsg = checker.InitChecker(name, val); if (errmsg != null) { throw new FormatException($"格式错误'{errmsg}'"); } return(checker); }
protected override string ToString(bool noBracket) { var name = (Attribute.GetCustomAttribute(GetType(), typeof(ValidNameAttribute)) as ValidNameAttribute).Names[0]; if (_Val == null) { return(name); } else { return($"{name} {_Operator.GetDesc()} {_Val}"); } }
public override string ToString() { return(Operator.GetDesc()); }