Skip to content

Allow to ref property #1644

Answered by stakx
mdmozibur asked this question in Q&A
Discussion options

You must be logged in to vote

What would the compiler do in this case:

object WeirdProperty
{
    get { return "howdy"; }
    set { SetFoo(IsFrobbled(value) ? SomeOtherProperty : someField + anotherField); }
}

especially when it might not even have the source available. It might have to decompile a property's accessors and somehow find out whether there is a mapping to exactly one backing field.

Properties are not required to have a backing field, or they might be several. Simply put, properties are not fields, and attempting to treat them as such isn't a good idea IMO.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by YairHalberstadt
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #1644 on October 16, 2020 08:08.