[Proposal] optional parameter implicit type conversion
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description


Due to the reason of the optional parameter its value required of the primitive type constant value, so that there is no way for using non-primitive value as the optional parameter its default value. So that this example code will throw the compiler error:
```vbnet
Sub Plot(Optional padding As Padding = New Padding(100, 100, 100, 100))
...
End Sub
```
But if assuming that we have define the ``CType`` implicit conversion for our non-primitive type creates from a primitive type value, then is there any possible to apply this implicit conversion on the optional parameter?

For example, we have creates a ``CType`` implicit conversion for type ``Padding`` convert from ``String`` type, so that we can using a constant string value ``padding: 100px 100px 100px 100px;`` as its optional parameter default value:
```vbnet
Sub Plot(Optional padding As Padding = "padding: 100px 100px 100px 100px;")
...
End Sub
```
Due to the reason of the optional parameter ``padding`` its default value is a string and this string value is also constant, so that this will not violate the rule of the optional parameter should be constant. and this default value can be stored in the compiled assembly as meta data as other optional parameter does.

This new feature will makes the VisualBasic coding more convenient when the function have a lot of the optional parameter.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.