【发布时间】:2021-06-02 00:03:51
【问题描述】:
我对下面发生的事情有点困惑:
谁能解释一下为什么 dataType 一直说 StatisticData 而不是 SibsMonthly?
dataType 是一个枚举? passad 作为 ref 参数传递给此方法,并在方法调用之前将其初始化为 null..
代码如下:
string errorMessage = null;
Enums.Uploads.DataType? dataType = null;
if (ValidadeFile(file, ref errorMessage, ref dataType))
{
...
}
private bool ValidadeFile(IBrowserFile file, ref string errorMessage, ref Enums.Uploads.DataType? dataType)
{
List<string> acceptedFileTypes = new List<string>
{
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
};
var valid = true;
if (AcceptedFileNames != null && AcceptedFileNames.Length > 0)
{
var tmp = AcceptedFileNames.Where(x => new Regex(x.Regex).IsMatch(file.Name))
.OrderByDescending(x => x.DataType)
.Select(x => x.DataType)
.FirstOrDefault();
dataType = tmp;
if (dataType == null)
{
valid = false;
errorMessage = Constants.Uploads.Error.InvalidFileName;
}
}
...
}
【问题讨论】:
-
你在调试正在运行的代码吗?还是有其他线程正在修改该成员?
-
我正在调试代码,没有其他线程正在运行.. 顺便说一下,我使用 ref 作为 dataType 及其可为空的,因此在方法调用之前将其初始化为 null
-
@BrianParker 我知道正则表达式,你可以在代码中读到它在 x.Regex 中的内容......
-
@Brian 整点是
dataType = tmp似乎没有更新变量dataType。 Linq 在这里不相关,OP 调用var tmp = ...FirstOrDefault(),因此获取tmp的查询不会再次评估或类似的东西。 -
伙计们,我相信它是 Blazor 部分代码的 VS 调试器错误,因为当它到达 api 时,值会更新。我应该删除这个问题吗?还是放在这里以防万一有人遇到同样的问题?
标签: visual-studio asp.net-core blazor