Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I implement members of internal interfaces
    text
    copied!<p>I have been refactoring the codebase of the project that I am currently on so that classes/interfaces which are not useful beyond the confines of the assembly should be declared as internal (rather than public). But I've run into a problem with the following code:</p> <pre><code>internal interface IFirstInterface { ... } internal interface ISecondInterface { IFirstInterface First{ get; } ... } public class Implementer : ISecondInterface { public IFirstInterface First {get; private set;} ... } </code></pre> <p>My questions:</p> <ol> <li><p>Why do members of internal interfaces have to be publicly implemented? If you implement the interface on an internal class, shouldn't the implemented members be internal? This is not a big issue since the interface members won't be publicly accessible anyway, given the class is internal. It just seems counter intuitive.</p></li> <li><p>The main problem is with the scenario above since I cannot have a public getter for IFirstInterface since it is purportedly an internal interface i.e. I get the following error from the compiler:</p></li> </ol> <blockquote> <p>Inconsistent accessibility: property type 'IFirstInterface' is less accessible than property 'Implementer.First'</p> </blockquote> <p>Is there any way around this?</p> <p><strong>Note</strong>: I realise that there is probably little value in this refactoring exercise but I thought it would be a good way for me to understand more deeply the implications of the internal modifier.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload