Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VB -> C#: Properties not handled correctly for ref extension methods #1158

Open
gaschd opened this issue Nov 11, 2024 · 0 comments
Open

VB -> C#: Properties not handled correctly for ref extension methods #1158

gaschd opened this issue Nov 11, 2024 · 0 comments
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@gaschd
Copy link
Contributor

gaschd commented Nov 11, 2024

When applying extension methods with ref parameters to properties, they should be handled in the same way as ref parameters in regular methods.

VB.Net input code

Public Class ExtensionMethodsRefPropertyParameter
    Public Property Number As Integer = 3
    Public Sub WithExtensionMethod()
        Number.NegEx()
    End Sub
    Public Sub WithMethod()
        Neg(Number)
    End Sub
End Class

Public Module MathEx
    <Extension()>
    Public Sub NegEx(ByRef num As Integer)
        num = -num
    End Sub
    Public Sub Neg(ByRef num As Integer)
        num = -num
    End Sub
End Module

Erroneous output

public partial class ExtensionMethodsRefPropertyParameter
{
    public int Number { get; set; } = 3;
    public void WithExtensionMethod()
    {
        this.Number.NegEx();
    }
    public void WithMethod()
    {
        int argnum = Number;
        MathEx.Neg(ref argnum);
        Number = argnum;
    }
}

public static partial class MathEx
{
    public static void NegEx(this ref int num)
    {
        num = -num;
    }
    public static void Neg(ref int num)
    {
        num = -num;
    }
}
1 target compilation errors:
CS0206: A property or indexer may not be passed as an out or ref parameter

Expected output

public partial class ExtensionMethodsRefPropertyParameter
{
    public int Number { get; set; } = 3;
    public void WithExtensionMethod()
    {
        int argnum = Number;
        argnum.NegEx();
        Number = argnum;
    }
    public void WithMethod()
    {
        int argnum = Number;
        MathEx.Neg(ref argnum);
        Number = argnum;
    }
}
              
public static partial class MathEx
{
    public static void NegEx(this ref int num)
    {
        num = -num;
    }    
    public static void Neg(ref int num)
    {
        num = -num;
    }
}

Details

  • Product in use: Test
  • Version in use: master abea701
@gaschd gaschd added the VB -> C# Specific to VB -> C# conversion label Nov 11, 2024
gaschd added a commit to gaschd/CodeConverter that referenced this issue Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

1 participant