我有下面的方法,我需要检查参数是空的还是空的。
public DB Where(string field, string operat, string value, string andOr, string field2, string operat2, string value2)
{
_Where = " WHERE " + field + " " + operat + " @" + field + "1 " + andOr + " " + field2 + " " + operat2 + " @" + field2 + "2 ";
_Params.Add(field + "1", value);
_Params.Add(field2 + "2", value2);
return this;
}
我找到了 string.IsNullOrWhiteSpace 方法,但这需要这么多代码:
if (string.IsNullOrWhiteSpace(field))
throw new ArgumentException("field Cannot be null or be empty");
if (string.IsNullOrWhiteSpace(operat))
throw new ArgumentException("operat Cannot be null or be empty");
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentException("value Cannot be null or be empty");
if (string.IsNullOrWhiteSpace(andOr))
throw new ArgumentException("andOr Cannot be null or be empty");
if (string.IsNullOrWhiteSpace(field2))
throw new ArgumentException("field2 Cannot be null or be empty");
if (string.IsNullOrWhiteSpace(operat2))
throw new ArgumentException("operat2 Cannot be null or be empty");
if (string.IsNullOrWhiteSpace(value2))
throw new ArgumentException("value2 Cannot be null or be empty");
有没有办法缩短这个?
另外,我尝试为这个任务创建一个自定义方法,但是它在自定义方法而不是 Where() 方法中引发了一个异常,这使得调试变得很棘手。