VB -> C#: wrong conversion of optional struct or decimal ref parameter
See original GitHub issueVB.Net input code
Private Shared Sub OptionalParams()
FunctionWithOptionalParams()
End Sub
Private Shared Sub FunctionWithOptionalParams(Optional ByRef structParam As TestStruct = Nothing, Optional ByRef decimalParam As Decimal = 0)
structParam = New TestStruct
decimalParam = 0
End Sub
Friend Structure TestStruct
Friend A As Boolean
End Structure
Erroneous output
private static void OptionalParams()
{
TestStruct argstructParam = null;
decimal argdecimalParam = 0m;
FunctionWithOptionalParams(structParam: ref argstructParam, decimalParam: ref argdecimalParam);
}
private static void FunctionWithOptionalParams([Optional, DefaultParameterValue(default(TestStruct))] ref TestStruct structParam, [Optional, DefaultParameterValue(0m)] ref decimal decimalParam)
Expected output
private static void OptionalParams()
{
TestStruct argstructParam = default;
}
private static void FunctionWithOptionalParams([Optional] ref TestStruct structParam, [Optional, DefaultParameterValue(0)] ref decimal decimalParam)
Details
- Product in use: VS extension
- Version in use: 9.0.0.0
- Did you see it working in a previous version, which? no
- may be, there is a better way to express DefaultParameterValue for a structure
Issue Analytics
- State:
- Created a year ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
VB -> C#: Convert optional ref parameters · Issue #91
In C# A ref or out parameter cannot have a default value Input code Public Class OptionalRefIssue91 Public Shared Function TestSub(Optional ...
Read more >A property or indexer may not be passed as an out or ref ...
Property or indexer may not be passed as an out or ref parameter at compile time. I even tried this: double.TryParse(objReader[i].ToString().
Read more >C#/VB struct – how to avoid case with zero default values ...
A constructor would perform the conversion from an input maxLength , or you could provide a private setter to keep the 10 localized...
Read more >Overload resolution
This chapter describes the rules that govern overload resolution when multiple members have the same name.
Read more >Conversions - C# language specification
This chapter covers the possible conversions from one type to another in C#. Builtin conversions, user defined conversions, implicit and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
private static void FunctionWithOptionalParams(ref TestStruct structParam, ref decimal decimalParam, ref string strParam, ref DateTime dateParam)
would break VB code calling converted C# code (in VB you can omit optional ref params)
Optional ByRef xxx As Short = 0S converts to [Optional, DefaultParameterValue(0)] out short xxx
should be [Optional, DefaultParameterValue((short)0)] out short xxx