我尝试使用short-hand重写此方法,如果:
public string checkInputParamters(string baseUrl, string owner, string documentId, string user, string secret, string type)
{
if (String.IsNullOrEmpty(baseUrl))
return ExceptionsCodes.BASE_URL_CANNOT_BE_NULL_OR_EMPTY.ToString("g");
if (String.IsNullOrEmpty(owner))
return ExceptionsCodes.OWNER_CANNOT_BE_NULL_OR_EMPTY.ToString("g");
return "";
}
Run Code Online (Sandbox Code Playgroud)
我不能这样做因为返回强迫我在":"iso";"之后加上一个值.
public string checkInputParamters(string baseUrl, string owner, string documentId, string user, string secret, string type)
{
return ((null == baseUrl) || (string.Empty == baseUrl)) ? ExceptionsCodes.BASE_URL_CANNOT_BE_NULL_OR_EMPTY.ToString("g");
return ((null == owner) || (string.Empty == owner)) ? ExceptionsCodes.OWNER_CANNOT_BE_NULL_OR_EMPTY.ToString("g");
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
另外需要注意的是你可以更换
((null == owner) || (string.Empty == owner))
Run Code Online (Sandbox Code Playgroud)
同
String.IsNullOrEmpty(owner)
Run Code Online (Sandbox Code Playgroud)
return String.IsNullOrEmpty(baseUrl)
? YourBaseUrlException
: String.IsNullOrEmpty(owner)
? YourOwnerException
: "";
Run Code Online (Sandbox Code Playgroud)