【问题标题】:Problem creating new Telerik DataSource implementation: "does not implement inherited abstract member 'DataSource.CreateClone()'"创建新 Telerik DataSource 实现时出现问题:“不实现继承的抽象成员 'DataSource.CreateClone()'”
【发布时间】:2020-06-30 10:42:00
【问题描述】:

我正在调查 Telerik 报告数据源的行为,因为我需要实现一个新的复杂数据源,该数据源与另一个以惰性方式向 Telerik 提供数据的进程协调。

现在,我想通过实现一个直接实现DataSource class 的模拟类来研究 Telerik 如何与指定的 DataSource 对话。

class MockDataSource : DataSource
{
    internal override object CreateClone()
    {
        throw new NotImplementedException();
    }
}

我添加了CreateClone 方法,因为编译器显示以下错误:

错误 CS0534 'MockDataSource' 没有实现继承的抽象成员 'DataSource.CreateClone()'

但即使使用添加的方法,上述错误也不会消失,而且添加的方法似乎什么都没有覆盖:

错误 CS0115 'MockDataSource.CreateClone()':找不到合适的方法来覆盖

我对 C# 很陌生,但我不知道为什么会发生这种情况; Telerik 文档也没有在任何地方说明自定义 DataSource 的可行性,这不是所提供的之一:https://docs.telerik.com/reporting/connecting-to-data-data-source-components

【问题讨论】:

  • 您可以尝试将您的覆盖修改为显式吗? Object ICloneable.Clone()。基本上将ICloneable. 添加到您的签名中。试一试,然后报告。祝你好运
  • 感谢您的建议;可悲的是它不起作用。特别是在CreateClone 方法的签名中仅添加ICloneable. 时,编译器错误提示'MockDataSource' 没有实现接口'ICloneable'
  • 然后我尝试将ICloneable 添加到类签名中,新错误消失了,但错误 CS0534 仍然存在...

标签: c# telerik telerik-reporting


【解决方案1】:

这些错误的原因在于抽象方法 CreateClone() 的可见性修饰符:在 JetBrains Rider 的帮助下检查从 DLL 反编译的库代码,可以看到该方法被声明为 internal

[...]

namespace Telerik.Reporting
{
  [SRCategory("DataSources_Category")]
  [ToolboxItemFilter("VS.Telerik.Reporting.14.1.20.513", ToolboxItemFilterType.Require)]
  public abstract class DataSource : Component, ISimpleDataSource, IDataSource, INamedObject, ICloneable
  {
    [...]

    internal abstract object CreateClone();

    [...]
  }
}

因此,我们需要重写的方法在 Telerik 的程序集之外是不可见的,因此实际上无法从第三方程序集扩展 DataSource 抽象类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    相关资源
    最近更新 更多