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#: Exclamation point operator treated as member access #479

Closed
GrahamTheCoder opened this issue Jan 5, 2020 · 0 comments
Closed
Assignees
Labels
Small Estimated less than 4 hours work VB -> C# Specific to VB -> C# conversion

Comments

@GrahamTheCoder
Copy link
Member

Input code

See https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/special-characters-in-code#exclamation-point--operator

Should probably have an Imports statement or two:

Public Class hasDefault
  Default Public ReadOnly Property index(ByVal s As String) As Integer
    Get
      Return 32768 + AscW(s)
    End Get
  End Property
End Class
Public Class testHasDefault
  Public Sub compareAccess()
    Dim hD As hasDefault = New hasDefault()
    MsgBox("Traditional access returns " & hD.index("X") & vbCrLf & 
      "Default property access returns " & hD("X") & vbCrLf & 
      "Dictionary access returns " & hD!X)
  End Sub
End Class

Erroneous output

using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;

public partial class hasDefault
{
    public int this[string s]
    {
        get
        {
            return 32768 + Strings.AscW(s);
        }
    }
}

public partial class testHasDefault
{
    public void compareAccess()
    {
        var hD = new hasDefault();
        MsgBox["Traditional access returns " + Conversions.ToString(hD["X"]) + Constants.vbCrLf + "Default property access returns " + Conversions.ToString(hD["X"]) + Constants.vbCrLf + "Dictionary access returns " + Conversions.ToString(hD.X)];
    }
}

Expected output

using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;

public partial class hasDefault
{
    public int this[string s]
    {
        get
        {
            return 32768 + Strings.AscW(s);
        }
    }
}

public partial class testHasDefault
{
    public void compareAccess()
    {
        var hD = new hasDefault();
        Interaction.MsgBox("Traditional access returns " + Conversions.ToString(hD["X"]) + Constants.vbCrLf + "Default property access returns " + Conversions.ToString(hD["X"]) + Constants.vbCrLf + "Dictionary access returns " + Conversions.ToString(hD["X"]));
    }
}
@GrahamTheCoder GrahamTheCoder added the VB -> C# Specific to VB -> C# conversion label Jan 5, 2020
@GrahamTheCoder GrahamTheCoder changed the title VB -> C#: _Add a short description_ VB -> C#: Exclamation point operator treated as member access Jan 5, 2020
@GrahamTheCoder GrahamTheCoder added the Small Estimated less than 4 hours work label Mar 7, 2020
@GrahamTheCoder GrahamTheCoder self-assigned this Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Small Estimated less than 4 hours work VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

1 participant