实现 DbCommand 并没有实现所有抽象类

发布于 2024-10-10 11:36:02 字数 827 浏览 0 评论 0原文

我尝试实现抽象 DbCommand 类(如 OdbcCommand、OleDbCommand,...),但我不明白的是为什么当我写:

internal sealed class SybaseCommand : DbCommand, IDisposable

并且我要求 VS2008 实现所有抽象类时,它不会自动生成每个方法/属性的所有重写存根。

这是 MSDN DbCommand 类:http://msdn。 microsoft.com/en-us/library/system.data.common.dbcommand.aspx

它不会为我生成“Connection”、“CanRaiseEvents”/...属性的存根,而不是存根对于 ExecuteReader()。

你能告诉我为什么吗?我错过了什么吗?

感谢您的帮助:)

[编辑]

对于 ExecuteReader() 方法,有 3 个方法

public DbDataReader ExecuteReader()
public DbDataReader ExecuteReader(CommandBehavior behavior)
protected abstract DbDataReader ExecuteDbDataReader(CommandBehavior behavior)

我可以假设这两个公共方法都只调用受保护的方法吗?

I try to implement the abstract DbCommand class (like OdbcCommand, OleDbCommand, ...) but a thing that I don't understand is why when I write :

internal sealed class SybaseCommand : DbCommand, IDisposable

and I ask VS2008 to implement all the abstract class, it doesn't generate automatically all override stub for each method / property.

Here is the MSDN DbCommand class : http://msdn.microsoft.com/en-us/library/system.data.common.dbcommand.aspx

It doesn't generate me the stub for the property for "Connection", "CanRaiseEvents" / ... and not the stub for ExecuteReader().

Can you tell me why? I've missed something?

Thanks for help :)

[EDIT]

In case of the ExecuteReader() method, there are 3 methods

public DbDataReader ExecuteReader()
public DbDataReader ExecuteReader(CommandBehavior behavior)
protected abstract DbDataReader ExecuteDbDataReader(CommandBehavior behavior)

Can I suppose that both public methods are only calling the protected one?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦妄 2024-10-17 11:36:02

正如 asawyer 所说,只有重写你实际上可以重写的方法和属性才有意义,即虚拟抽象成员。

要“覆盖”非虚拟或非抽象成员,您必须使用 修饰符。例如,

public new DbDataReader ExecuteReader()

这具有常见的缺点,如 MSDN 参考文章

As asawyer said, it is only meaningful to override methods and properties that you actually can override, i.e. virtual and abstract members.

To "override" non-virtual or non-abstract members, you have to use the new modifier. E.g.

public new DbDataReader ExecuteReader()

This has the usual drawbacks, as described in the MSDN reference article.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文