nameof operator length parameter #3455
Unanswered
Pentadome
asked this question in
Language Ideas
Replies: 2 comments
-
Related: |
Beta Was this translation helpful? Give feedback.
0 replies
-
I wonder if array slicing could be used insted of start + length syntax. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
nameof operator improvements
Proposed
Summary
The nameof operator gets an additional optional parameter, where the amount of property names, to be converted to a string property path, can be indicated.
Motivation
Often in Xamarin, you want to bind to a property of an property. This means that you want to use the nameof operator to specify the property path. Currently this is done this way:
This is a lot of boilerplate code for something that should be more simple.
Also, you might want to refer to a property of a property in an exception message.
Detailed design
nameof gets an additional parameter of type int where the length of the property path to convert to string can be indicated.
Drawbacks
At first glance, it might be unclear how long the property path is going to be,
Alternatives
The only alternative is provided in the proposal.
Unresolved questions
What happens when someone types in a higher number than the amount of properties?
What happens when someone uses a negative value?
Beta Was this translation helpful? Give feedback.
All reactions