Paste & Convert C# Code to Mercury not handling properties correctly

Using Water (version 11.0.0.2637), I tried out the menu option Edit => Paste => Paste & convert C# code, and the resulting code doesn’t seem quite right in three areas related to property definitions. This C# code:

   private string mString;

    public string[] Test
    {
        get
        {
            return mString;
        }

        set
        {
            mString = value;
        }
    }

Yields this Mercury code:

  Private Dim mString As String
  Public Property Test As String()
    Return Me.mString
  End Get
  Set
    Me.mString = value
  End Set
End Property

The things that look not quite right to me are:

  • I think it should be just “Private mString as String”, not “Private Dim mString as String”.
  • It is missing the initial “Get” statement,
  • Shouldn’t “Set” instead be “Set (value as String)”? (I might be wrong about that, as Mercury might allow this syntax.)

–Avonelle

That’s a matter of taste, surely?

yep, we’ll fix

Good Q, not sure. i believe “Value” is implied as name. i’ll check.

done.

this wont compile though, right? even in C#. type mismatch, array vs single string…

this compiles:

  Private Dim mString As String()
  
  Public Property Test As String()
    Get
      Return Me.mString
    End Get
    Set
      Me.mString = Value
    End Set
  End Property

so I won’t change the codegen for that, if thats ok,

Oh, duh, this is what happens you are trying to create a simple test example and it has already been a long week. Yep, should not have been an array, just a single string.

–Avonelle

If so, that is strange syntax to me. Usually it would either be “Private mString as String” or “Dim mString as String” but not “Private Dim mString as String”.

If I type “private dim mstring as string” into VS2019 w/o Mercury, it removes the “dim”.

–Avonelle

Curious.

VB documentation:

It’s optional, and thus allowed.

But I agree that we, as VB programmers, always skip the DIM keyword when it is preceded by a modifier.

@mh I agree with avonell that this use of the DIM keyword feels kind of alien.

1 Like

Thanks for researching this. You’ve taught me something new!

–Avonelle

I’ve changed CG4 to

        vbGenerateMemberTypeVisibilityPrefix(field.Visibility)
        vbGenerateStaticPrefix(field.Static && !type.Static)
        if field.Constant {
            Append("Const ")
        } else {
            if field.visibility == .Unspecified {
                Append("Dim ")
            }
        }

Another optional thing - from the VB documentation:

image

1 Like

Yeah, I recalled that it might be optional, but I was thinking it was a Mercury thing, not an optional VB thing. I’m certainly no expert on what is allowable VB.NET syntax - I guess I’ve fallen into a pattern on what works for me, and everything else looks strange to me!

The original code I was converting had lots of properties and most or all of them were missing the starting “Get” (and so it wouldn’t compile), so that’s what made me look closer. Probably if that wasn’t an issue, I wouldn’t have necessarily noticed/mentioned the other differences.

Thanks for the refresher!

–Avonelle