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

**URL:** https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946
**Category:** Water
**Tags:** mercury
**Created:** [June 17, 2021, 8:01pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946 "2021-06-17T20:01:27Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![avonelle](https://talk.remobjects.com/user_avatar/talk.remobjects.com/avonelle/32/13001_2.png) [@avonelle](https://talk.remobjects.com/u/avonelle)
#### Post date: [June 17, 2021, 8:01pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/1 "2021-06-17T20:01:27Z")

</div>

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:

```auto
   private string mString;

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

        set
        {
            mString = value;
        }
    }

```

Yields this Mercury code:

```auto
  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

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [June 17, 2021, 9:40pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/2 "2021-06-17T21:40:59Z")

</div>

> [@avonelle](#):
>
> - I think it should be just “Private mString as String”, not “Private Dim mString as String”.

That’s a matter of taste, surely?

> [@avonelle](#):
>
> It is missing the initial “Get” statement,

yep, we’ll fix

> [@avonelle](#):
>
> Shouldn’t “Set” instead be “Set (value as String)”? (I might be wrong about that, as Mercury might allow this syntax.)

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

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [June 17, 2021, 9:44pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/3 "2021-06-17T21:44:29Z")

</div>

> [@mh](#):
>
> > [@avonelle](#):
> >
> > It is missing the initial “Get” statement,
> 
> yep, will fix

done.

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [June 17, 2021, 9:45pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/4 "2021-06-17T21:45:44Z")

</div>

> [@avonelle](#):
>
> ```auto
> private string mString;
> 
> public string[] Test
> {
> get
> {
> return mString;
> }
> 
> ```

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

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [June 17, 2021, 9:46pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/5 "2021-06-17T21:46:18Z")

</div>

> [@mh](#):
>
> > [@avonelle](#):
> >
> > Shouldn’t “Set” instead be “Set (value as String)”? (I might be wrong about that, as Mercury might allow this syntax.)
> 
> Good Q, not sure. i believe “Value” is implied as name. i’ll check.

this compiles:

```auto
  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,

---

<div class="post-metadata">

### Author: ![avonelle](https://talk.remobjects.com/user_avatar/talk.remobjects.com/avonelle/32/13001_2.png) [@avonelle](https://talk.remobjects.com/u/avonelle)
#### Post date: [June 17, 2021, 10:01pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/6 "2021-06-17T22:01:27Z")

</div>

> [@mh](#):
>
> this wont compile though, right? even in C#. type mismatch, array vs single string…

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

---

<div class="post-metadata">

### Author: ![avonelle](https://talk.remobjects.com/user_avatar/talk.remobjects.com/avonelle/32/13001_2.png) [@avonelle](https://talk.remobjects.com/u/avonelle)
#### Post date: [June 17, 2021, 10:04pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/7 "2021-06-17T22:04:28Z")

</div>

> [@mh](#):
>
> > [@avonelle](#):
> >
> > - I think it should be just “Private mString as String”, not “Private Dim mString as String”.
> 
> That’s a matter of taste, surely?

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

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [June 18, 2021, 12:15pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/8 "2021-06-18T12:15:31Z")

</div>

> [@avonelle](#):
>
> If I type “private dim mstring as string” into VS2019 w/o Mercury, it removes the “dim”.

Curious.

---

<div class="post-metadata">

### Author: ![Theo69](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@Theo69](https://talk.remobjects.com/u/Theo69)
#### Post date: [June 18, 2021, 12:26pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/9 "2021-06-18T12:26:32Z")

</div>

VB documentation:

 ![image](https://talk.remobjects.com/uploads/default/original/2X/9/9a356e6c9c62804d94ee5ea09400faa7e78b3053.png)

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.

---

<div class="post-metadata">

### Author: ![avonelle](https://talk.remobjects.com/user_avatar/talk.remobjects.com/avonelle/32/13001_2.png) [@avonelle](https://talk.remobjects.com/u/avonelle)
#### Post date: [June 18, 2021, 12:28pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/10 "2021-06-18T12:28:22Z")

</div>

> [@Theo69](#):
>
> It’s optional, and thus allowed.

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

–Avonelle

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [June 18, 2021, 12:28pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/11 "2021-06-18T12:28:53Z")

</div>

I’ve changed CG4 to

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

```

---

<div class="post-metadata">

### Author: ![Theo69](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@Theo69](https://talk.remobjects.com/u/Theo69)
#### Post date: [June 18, 2021, 12:39pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/12 "2021-06-18T12:39:27Z")

</div>

> [@avonelle](#):
>
> Shouldn’t “Set” instead be “Set (value as String)”? (I might be wrong about that, as Mercury might allow this syntax.)

Another optional thing - from the VB documentation:

 ![image](https://talk.remobjects.com/uploads/default/original/2X/2/2777ac4490f7079b83dc2a38f69d2a1496fd7edd.png)

---

<div class="post-metadata">

### Author: ![avonelle](https://talk.remobjects.com/user_avatar/talk.remobjects.com/avonelle/32/13001_2.png) [@avonelle](https://talk.remobjects.com/u/avonelle)
#### Post date: [June 18, 2021, 2:05pm UTC](https://talk.remobjects.com/t/paste-convert-c-code-to-mercury-not-handling-properties-correctly/24946/13 "2021-06-18T14:05:29Z")

</div>

> [@Theo69](#):
>
> Another optional thing - from the VB documentation:
> 
> ![image](https://talk.remobjects.com/uploads/default/original/2X/2/2777ac4490f7079b83dc2a38f69d2a1496fd7edd.png)

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](http://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
