Skip to content

Implicit property backing fields #196

@AnthonyDGreen

Description

@AnthonyDGreen

Trying to eliminate some redundancy (and work) when declaring expanded properties. I propose that given this declaration:

Property P As T
    Get

    End Get
    Set(value As T)

    End Set
End Property

There is an implicit backing field named _P of type T that is property scoped (see #195).

  • It is only created if no field of that name exists already.
  • It is only emitted if it's referred to in either the getter or the setter.

So nothing would change about existing property declarations today but this broken code (assuming no field _P actually exists):

Property P As T
    Get
        Return _P
    End Get
    Set(value As T)
        _P = value
    End Set
End Property

Would compile under this proposal. This eliminates repeating the name P and the type T which makes changing both much easier. We could use a magic keyword to mean "the implicit backing field" like Field or _Value but why go through all of that when the convention for backing fields is pretty well known. Also, we want the maintain the convention that we use for auto-prop backing fields for binary serialization reasons. Convention over Configuration FTW!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions