Why does C# prohibit internal access on interface members? -


c# deliberately prevents me putting internal access modifier on interface members. i'm pretty sure had put additional effort implementing restriction when have allowed well.

there should reason spend effort - one?

for me useful have internal access modifiers on interfaces realize "mutability prevention outside". e.g. consider following interface:

interface imessage {     ...     datetime lastsenttimestamp { get; internal set; }     ... } 

internally, within message broker, able set lastsenttimestamp. external users of api should not able change it. of course ditch interface , use class instead, however, removes pros of interfaces (e.g. change implementation anytime, etc.)

q1: don't why restrict me. there particular reason?

q2: i'm looking workaround particular situation above. splitting interface in 2 (imessage , iinternalmessage) looks big pain in ass , not option left...

i guess conflict c# designers have seen cannot implement interface internal member outside of declaring assembly (and friend assemblies). of course, still useful if outside assemblies consume interface. on other hand can behavior second internal-only interface:

public interface ipublic { /* public members */ } internal interface iprivate : ipublic { /* additional members */ } 

and own classes implement iprivate. external code can use ipublic.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -