public bool VerifyRequired(out string error) { error = string.Empty; if (detailed.Count < 0) { error += "detailed is null"; return false; } var proInfo = this.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).ToList(); var notCon = new string[] { "detailed" , "vexplain" }; var sb = new StringBuilder(); foreach (var item in proInfo) { if (notCon.Contains(item.Name)) continue; var sv = item.GetValue(this); if (sv == null) sb.Append($"【{item.Name}】"); } detailed.First().VerifyRequired(ref sb); if (string.IsNullOrWhiteSpace(sb.ToString())) return true; error = $"{ sb.ToString()}不能为空或在指定范围!"; return false; }
public void VerifyRequired(ref StringBuilder sb) { var proInfo = this.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).ToList(); var notCon = new string[] { "remark" }; foreach (var item in proInfo) { if (notCon.Contains(item.Name)) continue; var sv = item.GetValue(this); if (sv == null) sb.Append($"【{item.Name}】"); } }
标签:detailed,string,VerifyRequired,item,var,sb From: https://www.cnblogs.com/valeb/p/16985389.html