Skip to content

VB -> C#: Language version seems to be ignored in some cases (C# 7 feature is used in C# 6 conversion request) #878

Closed
@N-Olbert

Description

@N-Olbert

VB.Net input code

Public Function Foo(x As Decimal) As Decimal
    If (x > "0") Then
	    Return x * "30,56" 
    End If
    Return Nothing 
End Function

Erroneous output

public decimal Foo(decimal x)
{
    if ((double)x > Conversions.ToDouble("0"))
    {
        return (decimal)((double)x * Conversions.ToDouble("30,55"));
    }

    return default; // NOTE: default is a C# 7 feature
}

Expected output

public decimal Foo(decimal x)
{
    if ((double)x > Conversions.ToDouble("0"))
    {
        return (decimal)((double)x * Conversions.ToDouble("30,55"));
    }

    return default(decimal); // NOTE: default(decimal) (this works in C# 6)
}

Converter code

var conversionOptions = new CodeWithOptions(code)
                                                .SetFromLanguage(LanguageNames.VisualBasic, 14)
                                                .SetToLanguage(LanguageNames.CSharp, 6) // NOTE: Language version is set to 6
                                                .WithTypeReferences(references);
var conversationResult = await CodeConverter.ConvertAsync(conversionOptions)

Details

  • Product in use: NuGet-package "ICSharpCode.CodeConverter"
  • Version in use: 8.5.0.374

Metadata

Metadata

Assignees

No one assigned

    Labels

    VB -> C#Specific to VB -> C# conversion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions