为什么我的方法不被调用?

编程入门 行业动态 更新时间:2024-10-25 12:20:45
本文介绍了为什么我的方法不被调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在运行一个在VS 2010 SP 1上编译的C#项目,在Windows 8机器上安装了.NET 4.5,我有一个如下所示的方法:

private IEnumerable< TModel> ExecuteAndGet< TModel>(string name,IEnumerable< SqlParameter>参数)其中TModel:new() {// < - Breakpoint 1 //非常简单代码,所以我怀疑方法调用被优化掉 //或者甚至有可能的事情。 }

在不同方法的同一个类中,我调用 ExecuteAndGet 像这样:

this.ExecuteAndGet< object>([dbo]。[SomeStoredProcedure] ,参数); //< - 断点2

这绝对是该方法唯一的重载。在调试模式下运行程序时,我打破了断点2.我已经尝试过常规的F5和步骤INTO,但是它完全跳过了方法,并且跳过了断点1.我不知道为什么会发生这种情况。其他调用 ExecuteAndGet 正在工作,我不明白为什么这是不同的。帮助吗?

谢谢。

解决方案

你不是实际列举。尝试:

this.ExecuteAndGet< object>([dbo]。[SomeStoredProcedure],参数).ToList();

I'm running a C# project compiled against .NET 3.5 in VS 2010 SP 1 on a Windows 8 machine with .NET 4.5 installed, if that matters.

I have a method that looks like the following:

private IEnumerable<TModel> ExecuteAndGet<TModel>(string name, IEnumerable<SqlParameter> parameters) where TModel : new() { // <-- Breakpoint 1 // Non-trivial code so I doubt the method call is being optimized away // Or something if that's even possible. }

In the same class in a different method I call ExecuteAndGet like so:

this.ExecuteAndGet<object>("[dbo].[SomeStoredProcedure]", parameters); // <-- Breakpoint 2

That's definitely the only overload of that method. While running the program in debug mode I hit breakpoint 2. I've tried just regular "F5" and "Step INTO" but it completely skips going inside the method altogether and it skips breakpoint 1. I have no idea why this is happening. Other calls to ExecuteAndGet are working and I don't see why this is any different. Help, please?

Thanks.

解决方案

You're not actually enumerating. Try:

this.ExecuteAndGet<object>("[dbo].[SomeStoredProcedure]", parameters).ToList();

更多推荐

为什么我的方法不被调用?

本文发布于:2023-11-03 16:01:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555519.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不被   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!