在另一个程序重写内部抽象方法 [英] Overriding an internal abstract method in another assembly

查看:205
本文介绍了在另一个程序重写内部抽象方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯目前正在使用其他.NET库C#项目。该库做(除其他事项外)解析序列成大树。所有项目都是某种类型继承自抽象类的。我需要稍微改变行为和子类自己(可以称之为 MySequence )。创建树后,我可以用我自己的类的对象替换一些树节点。

Im currently working on a c# project that uses another .net library. This library does (amongst other things) parse a sequence into a tree. All items are of some type that inherits from the abstract class Sequence. I needed to alter the behaviour slightly and subclassed Sequence myself (lets call it MySequence). After the tree was created, I could replace some tree nodes with objects of my own class.

现在,该库的新版本发布,并与下面的签名复制功能介绍:

Now, a new version of the library was published, and a Copy function with the following signature was introduced:

internal abstract Sequence Copy();

我想通过我的code到新版本,并覆盖它,但无论我做什么,我得到了两个错误:

I tried to adopt my code to the new version and override it, but whatever I am doing, I get the two errors:

MySequence 未实现继承的抽象成员 Sequence.Copy() MySequence.Copy():发现重写没有合适的方法

MySequence does not implement inherited abstract member 'Sequence.Copy()' MySequence.Copy()': no suitable method found to override

这是有道理的,因为它是抽象的( - >它必须被覆盖)和内部( - >它不能被覆盖,由于隐藏的可见性从组件外)

This makes sense, since it is abstract (--> it must be overwritten) and internal (--> it can not be overwritten, due to hidden visibility from outside the assembly)

所以,问题是,我明白为什么会这样,但不知道该怎么办反对。至关重要的是我的项目的子类

So, the problem is, I understand why this is happening, but dont know what to do against it. It is crucial for my project to subclass Sequence.

而我也是不明白的是,为什么内部抽象允许modfier摆在首位,因为它基本上允许全班所有子类从集之外! ?

And what I also dont understand is, why the internal abstract modfier is allowed in the first place as it basically permits any subclassing of the whole class from outside the assembly!?

有什么办法解决呢?通过反射什么?

Is there any way to solve this? Via reflection or something?

在此先感谢!

推荐答案

基本上,你的运气了不会改变库。有可能是序列的一个子类,它实现复制,您可以从在新版本中得到。但它很可能是该复制方法是在库的其它部分需​​要创建克隆

Basically, you are out of luck without altering the library. There may be a subclass of Sequence that does implement Copy, which you can derive from in the new version. But it is likely that the Copy method is need in other parts of the library to create clones.

这篇关于在另一个程序重写内部抽象方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆