【发布时间】:2014-01-03 13:18:40
【问题描述】:
我有一个简短的问题,关于我从 Visual Studio 中的 Resharper 收到的关于我正在工作的 c# 项目的警告。警告是:
"未使用纯方法的返回值"
发生这种情况的方法如下:
private static bool FilePathHasInvalidChars(string userInputPath)
{
try
{
//this is where the warning occurs:
Path.GetFullPath(userInputPath);
}
catch (Exception e)
{
Log.Error(String.Format(
"The Program failed to run due to invalid characters or empty " +
"string value for the Input Directory. " +
"Full Path : <{0}>. Error Message : {1}.",
userInputPath, e.Message), e);
return true;
}
return false;
}
我想我知道为什么会发生警告。
我使用Path.GetFullPath(path) 只是为了捕获与无效字符有关的所有异常。该路径将由用户作为输入提供,因此我实际上并未使用Path.GetFullPath(userInputPath) 的结果。我对它的唯一用途是检查我对此方法的检查是检查我对 main 方法所做的检查,以确保提供的路径不为空或没有任何无效字符。
我使用上述方法的地方如下:
if (FilePathHasInvalidChars(inputDirectory))
{
return;
}
基本上它只是程序使用无效参数开始执行之前的退出点。
我想知道这个警告是否会导致任何问题,或者我是否滥用Path.GetFullPath 方法会在将来给我带来问题?
【问题讨论】:
标签: c# .net path directory resharper