简体   繁体   English

如何在调试时获得返回值?

[英]How do I get the return value while debugging?

I looked through SO but couldn't find the answer, I'm sure it's there though...? 我看了看SO,但找不到答案,我确定它在那里虽然......?

While debugging, how do I get the value of the return statement if I put a breakpoint on it? 在调试时,如果我在其上放置断点,如何获取return语句的值? I like to condense to a single line just so it looks "pretty". 我喜欢凝聚成一条线,只是看起来很漂亮。 But I currently don't since I can't figure out how to debug the returned result...? 但我目前没有,因为我无法弄清楚如何调试返回的结果......?

using (IUnitOfWork context = new EFUnitOfWork())
{
    var repo = new ReportRepository(context);
    return repo.GetProcedureReport(startDate, endDate).ToList();
    //return result.ToList();
}

In VS 2013, you can add the variable $ReturnValue to the watch. 在VS 2013中,您可以将变量$ ReturnValue添加到手表中。 It contains the actual returnvalue from the function. 它包含函数的实际返回值。

Select the method and right-click. 选择方法并单击鼠标右键。 Select Quickwatch from the menu. 从菜单中选择Quickwatch。

在此输入图像描述

I'm assuming you cannot put a breakpoint within GetProcedureReport ? 我假设你不能在GetProcedureReport放一个断点?

The type of return value debugging you're attempting is simply not possible with managed languages like C#. 您正在尝试的返回值调试类型对于C#等托管语言是不可能的。 The C++ debugger provides this information, via the autos window, but not managed languages. C ++调试器通过autos窗口提供此信息,但不提供托管语言。

The primary reason why is that the CLR debugging engine simply doesn't provide this value. 主要原因是CLR调试引擎根本不提供此值。 For C#, VB or F# to provide this they would need to rewrite every return statement to spill the value into a temporary and then return the temporary. 对于C#,VB或F#来提供这个,他们需要重写每个return语句以将值溢出到临时值然后返回临时值。 Return value debugging could then be achieved by surfacing this temporary in the debugger. 然后可以通过在调试器中显示临时值来实现返回值调试。

var returnTemp = repo.GetProcedureReport(startDate, endDate).ToList();
return returnTemp;

This would work but it would provide negatives to the code. 这可以工作,但它会给代码带来负面影响。 Most notably that big struct values would end up being copied twice and contribute negatively to performance. 最值得注意的是,大结构值最终会被复制两次并对性能产生负面影响。 Additionally this rewrite would need to occur at compile time and would affect every method being compiled. 此外,这种重写需要在编译时进行,并且会影响正在编译的每个方法。 It would be much less impactful if it could be done on demand at debug time. 如果可以在调试时按需完成,那么影响会小得多。 The negatives just out weigh the benefits here. 这些消极因素只是权衡了这里的好处。

Note that VB.Net does provide return value debugging to a small degree. 请注意,VB.Net确实在很小程度上提供了返回值调试。 I've blogged about how that works here 我在博客上写了这是如何工作的

http://blogs.msdn.com/b/jaredpar/archive/2011/01/12/why-the-debugging-difference-between-c-and-vb-net-return-values.aspx http://blogs.msdn.com/b/jaredpar/archive/2011/01/12/why-the-debugging-difference-between-c-and-vb-net-return-values.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得SP返回值? - How do I get an SP return value? 在VS2008中调试时如何发现函数末尾的返回值? - How do I discover the return value at the end of a function when debugging in VS2008? 如何在调试时使用除ToString之外的委托来显示对象的值? - How do I use a delegate other than ToString to show an object's value while debugging? 在调试Visual Studio 2010 MVC C#程序时如何从键盘获得输入? - How do I get input from the keyboard while debugging a Visual Studio 2010 MVC C# program? 如何从Button Click事件中获取返回值? - How do I get a return value from a Button Click event? 如何在回调中获取DispatcherOperation的返回值 - How do I get the return value of DispatcherOperation inside the callback 如何使用 Dapper 获取存储过程的返回值? - How do I use Dapper to get the return value of stored proc? 如何获取任务的结果或返回值? - How do I get the result or return value of a Task? 在 Visual Studio 中调试时,我可以在返回之前找出返回值吗? - Can I find out the return value before returning while debugging in Visual Studio? 如何使用return返回数据库的返回值? - How do i get the return value coming a database with just using return?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM