In my function, I get objects that implement the IMediaPanel
interface:
public interface IMediaPanel { bool IsListsAreaVisible { get; } bool IsNextEntityExists { set; } } private void InitConnections(IMediaPanel panelControl) {
During initialization, I need to specify the property names for which I use the C # 6.0 nameof
keyword:
nameof(IMediaPanel.IsListsAreaVisible)
This works fine, but with this expression:
nameof(IMediaPanel.IsNextEntityExists)
Visual Studio shows me the following error:
The property "MyNamespace.IMediaPanel.IsNextEntityExists" has no recipient.
The search for "name restrictions" did not give me an answer to this question; moreover, official comments do not contain restrictions on getters properties:
... The following errors should be noted: predefined types (for example, int or void), types with a null value (Point?), Array types (Customer [,]), pointer types (Buffer *), qualified alias (A :: B ) and unrelated common types (Dictionary <,>), preprocessing characters (DEBUG), and labels (loop:) ....
Can someone explain why this restriction exists, and if there is any link to it? What reason can force the nameof
keyword to use an attribute of a property instance while it should (as I assume) just use generic type information through Reflection? (at least in this particular case, when I cannot directly specify an instance property due to an unknown type, I just know that this instance implements the interface)
Update
To explain why the @Gusdor suggestion from the comments does not work, I need to clarify what I call the InitConnections
function (in simplified form):
public void Init(FrameworkElement panelControl) {
So, if I use nameof(panelControl.IsNextEntityExists)
inside the Init function, this will nameof(panelControl.IsNextEntityExists)
an error because FrameworkElement does not contain the custom client property IsNextEntityExists
. And if I use the same expression inside the InitConnections function, I get an error message - the same as with nameof(IMediaPanel.IsNextEntityExists)
.
Anyway, I found the answer, this "getter" error is a ReSharper error (see my own answer).