要写一个common method来解析上节编写的TTServer Export导出的xml,但是查询条件会发生变化,经过研究,使用三木运算符可以解决这种问题,废话不多说,上代码:
private int QueryDefectNum(string type, string creater, string status, DateTime start, DateTime end)
{
var query = from defect in element.Descendants("Defect")
where
(!string.IsNullOrEmpty(type) ? defect.Element("type").Value.contains(type) : true) &&
(!string.IsNullOrEmpty(creater) ? defect.Element("creater").contains(creater) : true) &&
(!string.IsNullOrEmpty(status) ? defect.Element("status").contains(status) : true) &&
Convert.ToDateTime(defect.Element("date-created").Value) >= start &&
Convert.ToDateTime(defect.Element("date-created").Value) <= end
select defect;
return query.count;
}
本文介绍了一个通用方法用于查询TTServerExport导出的XML文件。通过使用三元运算符和LINQ查询,该方法能够灵活地根据不同的查询条件筛选出目标缺陷记录。
7147

被折叠的 条评论
为什么被折叠?



