paul1956 / CSharpToVB

New version of CSharpToVB converter
MIT License
25 stars 9 forks source link

Parameters and property names conflictions #38

Closed VBAndCs closed 4 years ago

VBAndCs commented 4 years ago

C#:

        public override void Write(char[] buffer, int index, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (index < 0 || index >= buffer.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            if (count < 0 || (buffer.Length - index < count))
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            Buffer.AppendHtml(new string(buffer, index, count));
        }

VB.NET:

Option Compare Text
Option Explicit On
Option Infer Off
Option Strict On
Public Overrides Sub Write(buffer As Char(), index As Integer, count As Integer)
    If buffer Is Nothing Then
        Throw New ArgumentNullException(NameOf(buffer))
    End If

    If index < 0 OrElse index >= buffer.Length Then
        Throw New ArgumentOutOfRangeException(NameOf(index))
    End If

    If count < 0 OrElse (buffer.Length - index < count) Then
        Throw New ArgumentOutOfRangeException(NameOf(count))
    End If

    Buffer_Renamed.AppendHtml(New String(buffer, index, count))
End Sub

the Buffer_Renamed.AppendHtml(New String(buffer, index, count)) is wrong. Buffer is not buffer in C#. As I mentioned b4, changing param name leads to errors in EF and other tech. so the only solution is to add Me. b4 any variable has the same name as a param but starting with Uppercase letter. Me.Buffer_Renamed.AppendHtml(New String(buffer, index, count)) is the equivalent VB for: Buffer.AppendHtml(new string(buffer, index, count));

And by the way, turn Option Infer On, as it is the default for C#, and turning it of causes errors in VB.

paul1956 commented 4 years ago

You can control Options that are generated in output file and that are used for testing under Options/Advanced Options....I have changed the code to add Me. in next version but not sure it will not break something else.