dotnet / dotnet/vblang

Generic Property?

Open
#96 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

### 1. Allow Generic on the Property?

Currently in vb, we can declare a property with parameters and use the property like normal function, but with a small difference, that the property didn't have the generic type parameter as the generic method it does. So I can not write something like:

```vbnet
Public Property Evaluate(Of T)(name$) As T()
```

For returns/set a generic type value, I have to using the ``Object`` type for implements this property, and facing the unavoidable boxing and unboxing:

```vbnet
Public Property Evaluate(name$) As Object()
Get
' blablabla
End Get
Set
' blablabla
End Set
End Property
```

### 2. Allow ParamArray on the Property Set value Parameter?

Recently i was implemented a tools for [**modify the array object property value in a vector programming style**](https://github.com/xieguigang/sciBASIC/blob/62fd61ead566d360c091dc0c7df7b085aab3ca93/Microsoft.VisualBasic.Architecture.Framework/Extensions/Reflection/Delegate/DataValue.vb#L36). I want to implements this tools in a more generic way for its set value property method and make it compatible with both set a single value or a value vector.

The normal method in vb its parameter can have a decorate of ``ParamArray``, so that we can input the array parameter in a more naturally way. but the property set method it doesn't, so that i have to write a code like:

```vbnet
Dim vector As NamedValue(Of String)() = {}
Dim previousData$() = Linq.DATA(vector).Evaluate("Value")

Linq.DATA(vector).Evaluate("Value") = {} ' set all value property to nothing
Linq.DATA(vector).Evaluate("Value") = {"1"} ' set all value property to a specific value "1"
Linq.DATA(vector).Evaluate("Value") = {"1", "2", "3"}
```

So I think probably the property set method can act as the same the normal method, allowing user able to add type generic and ``ParamArray``:

```vbnet
Public Property Evaluate(Of V)(name$) As V()
Get
' blablabla
End Get
Set(ParamArray value As V())
' blablabla
End Set
End Property
```

So that the user can write a more brief code in an elegant way like:

```vbnet
Dim vector As NamedValue(Of String)() = {}
Dim previousData$() = Linq.DATA(vector).Evaluate(Of String)("Value")

Linq.DATA(vector).Evaluate(Of String)("Value") = Nothing ' set all value property to nothing
Linq.DATA(vector).Evaluate(Of String)("Value") = "1" ' set all value property to a specifc value "1"
Linq.DATA(vector).Evaluate(Of String)("Value") = {"1", "2", "3"}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.