我有一个类的层次结构:
class C1 { virtual object M1(); }
class C2: C1 { override sealed object M1(); }
class C3: C2 {
// I want to override M1()
// CSC gives me an error, obviously
override object M1();
}
Run Code Online (Sandbox Code Playgroud)
但似乎有一种方法.在IL中,您可以使用其他名称覆盖方法.所以,我们更改名称(M1_2()覆盖M1()),说它覆盖了基类(C1::M1())上的方法,一个显式接口实现,而中间(C2)类上的"final" 不再重要.
.class public auto ansi beforefieldinit N.C3
extends N.C2
{
.method private hidebysig virtual final
instance object M1_2() cil managed
{
.override N.C1::M1
Run Code Online (Sandbox Code Playgroud)
ILasm很乐意组装它,它在ILSpy中显示为
public class C3 : C2
{
object …Run Code Online (Sandbox Code Playgroud)