c# - Abstract method in public abstract class implementing an internal interface doesn't compile? -
internal interface i_foo { void bar(); } public abstract class a_foo : i_foo { public a_foo() { } abstract void i_foo.bar(); } public class foo : a_foo { public foo() : base() { } internal override void bar() { } }
hello! i'm trying have methods visible outside code, , other visible assembly. purpose, made internal interface i_foo serve contract other parts of assembly, public abstract a_foo serve abstraction external code, , centralize constructor functionality, , several different classes foo implement a_foo , i_foo explicitly retain internal modifier.
however, in a_foo class, get
'a_foo.i_foo.bar()' must declare body because not marked abstract, extern, or partial
even though method marked "abstract". if add body, "abstract not valid modifier".
i need method explicitly declared, in order internal in public class, , need abstract can override in actual implementation foo.
why doesn't compiler let me? there way can achieve same thing? thank you.
explicit interface implementations have have actual implementation. trick here making call non-explicit (internal) abstract method:
public abstract class a_foo : i_foo { // classes outside assembly can't derive a_foo // anyway, let's make constructor internal... internal a_foo() { } void i_foo.bar() { bar(); // delegate abstract method } internal abstract void bar(); }
this still allows i_foo
use internal types etc, because bar
never exposed publicly - fits within other rules of language.
Comments
Post a Comment