Is there a reason we have to set the field in the set accessor in expression body? #4048
-
I'm just curious if there's a reason we still have to specify
I know we can infer that the consumer is intending to set the underlying field to the incoming value:
But does this lead to unexpected behaviors? I know the LDT has a reason for everything they do so I figure here is the best place to ask. Oh, if this was implemented in a version beyond 7.2 then ignore me. 😄 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Non-auto-properties don't have an underlying field. They are a totally self-contained member and the accessor is expected to perform any assignments. The return type for a There are proposals out there to blur the line between auto-properties and normal properties, however if you are required to explicitly name your fields due to binary serialization concerns then they won't help. Although you should be able to use field-targeting attributes to instruct the serializer/deserializer to give that generated field a different name, I think. |
Beta Was this translation helpful? Give feedback.
Non-auto-properties don't have an underlying field. They are a totally self-contained member and the accessor is expected to perform any assignments. The return type for a
set
access isvoid
so any result from an expression would just be discarded. You're expected to put a statement in the accessor to actually make the assignment to a field.There are proposals out there to blur the line between auto-properties and normal properties, however if you are required to explicitly name your fields due to binary serialization concerns then they won't help. Although you should be able to use fi…