可以将DebuggerStepThrough继承到自动生成的IEnumerable实现中吗? [英] Can DebuggerStepThrough be inherited into the automatically generated IEnumerable implementation?
问题描述
DebuggerStepThrough 属性可让您跳过在某些方法/类/属性中。
The DebuggerStepThrough attribute allows you to skip breaking into certain methods/classes/properties.
在 DebuggerStepThrough被忽略它被澄清,c#编译器不会将此属性继承到编译器生成的 IEnumerable< T>
实现中。
In DebuggerStepThrough being ignored it is clarified that the c# compiler does not inherit this attribute into the compiler generated IEnumerable<T>
implementation.
这种失败的一个简单的例子是:
A trivial example of such a failure is:
static void Main(string[] args)
{
var a = SkipMe().ToList();
}
[System.Diagnostics.DebuggerStepThrough]
static IEnumerable<int> SkipMe()
{
// comment out line below and the throw will be stepped over.
yield return 1;
throw new Exception();
}
有没有办法让C#编译器添加 DebuggerStepThrough
属性到自动生成的类型?
Is there a way to get the C# compiler to add the DebuggerStepThrough
attribute to the auto generated type?
有没有办法让visual studio使用 [CompilerGenerated]
属性跳过任何类型的调试?
Is there a way to get visual studio to skip debugging into any types with the [CompilerGenerated]
attribute?
-
附录:一些说明性的截图
Addendum: some illustrative screenshots
按 F5后的结果
Visual Studio版本:
Visual Studio Version:
我们缺少的属性:
推荐答案
我不要以为有办法达到你要找的效果。
I don't think there is a way to achieve the effect you're looking for.
- 没有办法使C#编译器将此属性复制到生成状态机方法中。
- 您不能通过将
DebuggerStepThrough
添加到包含迭代器方法的类中来解决此问题。调试器只查看直接父类型,而不是包含嵌套类型的类型。
- There is no way to make the C# compiler copy this attribute into the generate state machine method.
- You can't get around this by adding
DebuggerStepThrough
to the class containing the iterator method. The debugger only looks at the immediate parent type not the types containing a nested type.
我可以想到的唯一真正的方法这是把你不想调试的所有代码放在一个单独的DLL中。然后不要加载该特定DLL的PDB。
The only real way I can think of to achieve this is to put all of the code you don't want to debug into in a separate DLL. Then don't load the PDB for that particular DLL.
这篇关于可以将DebuggerStepThrough继承到自动生成的IEnumerable实现中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!