如何打破 C# 自动构造函数块?
我想知道是否有任何方法可以将断点放入自动构造函数/对象初始值设定项块内?
示例:
var x = new Person()
{
Name = 'John',
Age = DateTime.Now - Birthdate
}
我想在第四行放置断点。当为每个属性设置 150 个具有不同逻辑的字段并且您要创建实例的类型不受您的控制(例如 EF4 实体)时,这非常有用,因此您无法创建自定义构造函数。有什么想法吗?
I was wondering if there are any way to put break point inside an automatic constructor/object initializer block?
Example:
var x = new Person()
{
Name = 'John',
Age = DateTime.Now - Birthdate
}
I want to put breakpoint on the 4th line. This is very helpful when setting like 150 fields with different logic for each property and the type you are creating an instance of is not under your control (e.g. EF4 entity), therefore you cannot create a custom constructor. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
解决此问题的一个解决方法是编写如下代码以简化调试:
A workaround you can use for this issue is writing the code like this to ease your debugging:
如果
Name
属性不是自动的,您可以在该属性的set
内放置一个断点。If
Name
property is not automatic you can put a breakpoint insideset
of that property.将值包装在自调用函数中想要断点的行上:
现在您将能够“单步执行”它。不过,它没有多大用处,因为 x 将保持为空,直到块结束。
Wrap the value on a line where you want a breakpoint in a self calling function:
Now you will be able to "step into" it. It won't be of much use, though, as x will remain null until the end of the block.
如果你这样做的话你就不能。您可以在整个块上设置断点并使用 F11 单步执行它。
你为什么不做以下事情
If your doing it that way then you can't. You can out a breakpoint on the entire block and step through it using F11.
Why dont you do the following