public static string Replace(object obj, string template) { var matches = Regex.Matches(template, PropHolder); foreach (Match match in matches) { var replayFlag = match.Value; var propName = replayFlag.Trim("{} ".ToCharArray()); var propVal = RepoHelper.TryGetValue(obj, propName); var value = propVal == null ? string.Empty : propVal.ToString(); template = template.Replace(replayFlag, value); } return(template); }
public void Bind(object obj) { var leftVal = RepoHelper.TryGetValue(obj, Left); var op = OP.ToLower(); if (op == "like") { Value = leftVal.ToString().Contains(Right.ToString()); return; } if (leftVal == null) { Value = Right == null; return; } var result = ((IComparable)leftVal).CompareTo(Right); switch (op) { case "=": Value = result == 0; break; case ">": Value = result > 0; break; case ">=": Value = result > 0 || result == 0; break; case "<": Value = result < 0; break; case "<=": Value = result < 0 || result == 0; break; default: throw new ArgumentException("不支持符号" + OP); } }