In my function I receive objects implementing IMediaPanel
interface:
public interface IMediaPanel
{
bool IsListsAreaVisible { get; }
bool IsNextEntityExists { set; }
}
private void InitConnections(IMediaPanel panelControl)
{
// Initialization logic
}
During the initialization I need to specify properties' names, for which I'm using 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 getter.
Searching "nameof limitations" didn't give me any answer about this issue, moreover official remarks doesn't contain restriction about property getters:
... The following are worth mentioning that produce errors: predefined types (for example, int or void), nullable types (Point?), array types (Customer[,]), pointer types (Buffer*), qualified alias (A::B), and unbound generic types (Dictionary<,>), preprocessing symbols (DEBUG), and labels (loop:). ...
Can anyone explain why there is this restriction and if there is any reference about that? What reason can force nameof
keyword to use property's instance getter while it should (as I guess) just use general type information through Reflection? (at least in this particular case, when I can't directly point to an instance's property due to unknown type, I just know that this instance implements the interface)
To explain why @Gusdor's suggestion from comments is not working, I need to clarify how I call InitConnections
function (in simplified form):
public void Init(FrameworkElement panelControl)
{
// ... Other logic ...
this.InitConnections((IMediaPanel) panelControl);
}
So if I use nameof(panelControl.IsNextEntityExists)
inside Init function, it will produce an error because FrameworkElement doesn't contains custom client's IsNextEntityExists
property.
And if I use the same expression inside InitConnections function, I get an error about the getter - the same as with nameof(IMediaPanel.IsNextEntityExists)
.
Anyway, I found the answer, this 'getter' error is a ReSharper's bug (see my own answer).
It turned out a ReSharper bug, at least the error is not showing when ReSharper is suspended (Tools -> Options -> ReSharper Ultimate -> Suspend Now), and project successfully compiles even with errors displayed in Visual Studio.
My current versions are:
While I was searching how to submit bugs to the ReSharper team, I found a very similar issue in their tracker. It is about class member property, but it gives me the same error as with my interface, so I believe this is the same bug. There said it will be fixed in ReSharper 10.1.
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