Why am I not allowed to implement an internal interface in an internal class? Is there a specific reason for this restriction or is it just a language design decision?
internal interface IDefinition
{
string GetValueAsString(string property);
}
internal sealed class DefinitionArray : IDefinition
{
internal string GetValueAsString(string property)
{
return m_definitionRows
.Select(o => o.GetValueAsString(property))
.FirstOrDefault();
}
}
§3.5.6 of the C# 6.0 Language Specification states:
Interface members implicitly have
publicdeclared accessibility. No access modifiers are allowed on interface member declarations.
So what you 'theoretically' have is
internal interface IDefinition
{
public string GetValueAsString(string property);
}
But this is not a problem, since (§3.5.2):
The accessibility domain of a nested member
Mdeclared in a typeTwithin a programPis defined as follows (noting thatMitself may possibly be a type):
- If the declared accessibility of
Mispublic, the accessibility domain ofMis the accessibility domain ofT.
So the accessibility of the member is equivalent as it would have been declared as internal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With