[Proposal] Extension Property?
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
As all we knowns that since VB6, the ``Property Procedures`` in VisualBasic is consist with a paired method and function which have name prefix ``Get`` and ``Set``. The vb6 compiler can automatic properties this paired method as Class property.
**Sometime we just want a light weight class type without too many function and property, and using the extension method can simply extend this light weight class type and add more function based on our different demands.** But as so far, we don't have the extension property yet, but we can doing something currently like:
```vbnet
' ReadOnly Property
Public Sub SetLast(list As List(Of Foo), value As Foo)
' blablabla
list(-1) = value
End Sub
' WriteOnly Property
Public Function GetLast(list As List(Of Foo)) As Foo
' blabla
Return list(-1)
End Function
```
So that I think why don't we just enable using this extension method way to add a extension property as the VB6 it does?
The compiler match this two extension function their name with rule: **Set<Name>** and **Get<Name>**, so that we can paired these two extension method as an extension property.
Then we use such extension method as in sciBASIC it does: https://github.com/xieguigang/GCModeller/blob/7f44b456e1df40b450614a21769126c4f23c35f8/src/interops/localblast/LocalBLAST/LocalBLAST/LocalBLAST/Application/COG/Whog/Category.vb#L110
```vbnet
Dim list As New List(Of NamedValue)
' blablabla
list.Last = New NamedValue With {
.name = list.Last.name,
.text = list.Last.text & " " & Trim(nid.Value)
}
```
For the parameter property, that we can
```vbnet
' ReadOnly Property
Public Sub SetCompute(list As List(Of Foo), Name$, value As Foo)
' blablabla
End Sub
' WriteOnly Property
Public Function GetCompute(list As List(Of Foo), Name$) As Foo
' blabla
End Function
' using extension property
Data.Compute(Name) = Data2.Compute(Name)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.