c# - 为什么在 linq 语句中忽略 DebuggerStepThrough?

标签 c# visual-studio-2010 linq debugging breakpoints

在单步执行我的代码时,我发现某些行深处忽略了 DebuggerStepThrough 属性。它似乎适用于 linq 语句。

这是一个类似的 SO:DebuggerStepThrough being ignored

被逐步执行的代码处于 Debug模式。它与下面的 ReflectionHelper 方法在同一个解决方案中。项目引用是通过项目而不是其他地方的编译 dll,即与项目相同的输出 bin/debug 文件夹。没有其他异常情况表明正在使用的程序集与在两个项目端进行代码更改时会注意到的不同。

因此,当我逐步使用 F11 时,它会进入下面的代码。

我的 public static class ReflectionHelper 中有以下内容

[DebuggerStepThrough]
public static bool Exists(string propertyName, object srcObject)
{
    PropertyInfo propInfoSrcObj = srcObject.GetType().GetProperties()
        .FirstOrDefault(p => p.Name == propertyName); //-- Debugger stops here
    return (propInfoSrcObj != null);
}

enter image description here 我怎样才能避免这段代码单步执行?我目前的解决方法是 SHIFT+F11 在使用 F11 恢复调试之前退出。

发生这种情况的另一个例子是这段代码。

string databaseNamePair = split.Find(f => f.StartsWith("Initial Catalog")); 

最佳答案

那些 Linq 语句包含编译为方法调用的 lambda 表达式。因此,该属性不适用于这些不同的方法。

我想您可以将 lambda 转换为成熟的方法,以便您可以使用该属性标记它们,但这会导致代码错误。

关于c# - 为什么在 linq 语句中忽略 DebuggerStepThrough?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17800113/

相关文章:

c# - 是按ASCII代码在LINQ中排序吗?

c# - 如何调用 Dictionary<K, V>.TryGetValue() where K : Predicate<T>, V : enum

visual-studio-2010 - Visual Studio 2010 数据库项目无法识别 SQL 2008 地理数据类型

c# - 如何让自动生成的文件识别它自己创建的方法?

c++ - 64 位 Windows 上的 Boost.Test

c# - 根据另一个元素值选择 XML 元素

c# - 在 ASP.NET Web Config 中加密连接字符串

c# - 从 CodeBehind 访问 DataTemplate 中的 XAML 控件?

c# - 使用 WMI 读取注册表项

c# - 将char数组转换为int数组c#