question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VB -> C# Parameterized property

See original GitHub issue

Input code

        Public ReadOnly Property FullName(ByVal lastNameFirst As Boolean) As String
            Get
                If lastNameFirst Then
                    Return LastName & " " & FirstName
                Else
                    Return FirstName & " " & LastName
                End If
            End Get
        End Property

Erroneous output

        public string FullName
        {
            get
            {
                if (lastNameFirst)
                    return LastName + " " + FirstName;
                else
                    return FirstName + " " + LastName;
            }
        }

Expected output

        public string  FullName(bool lastNameFirst)
        {
                if (lastNameFirst)
                    return LastName + " " + FirstName;
                else
                    return FirstName + " " + LastName;
        }

Details

Product in use: VS extension

Version in use: 6.1.0.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
vflecommented, Nov 12, 2018

Sadly all i can help with is identify and workarounds.

Speaking of which, in case anyone else wants to change it before converting it to C# here is a regex to identify the parameterized properties.

Property?\s+(\w+)\s*(\([^()]+\))

0reactions
GrahamTheCodercommented, Nov 13, 2018

Nice investigation. Yep I usually look at the decompiled IL version of a VB assembly using the feature to see if I can at least take some inspiration. Obviously it doesn’t always map across nicely though. Since the setter sounds like a complicated (and not super-common) case, I’d happily take a PR that only works in C# 7.3+ if you can get it working. ref sounds like a plausible way to get it working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the difference between a parameterized property ...
Based on this principle, the most common use case for parameterized properties in VB.NET is in classes that represent a sequence of items, ......
Read more >
Property Statement - Visual Basic
This parameter holds the value to be assigned to the property. You typically store this value in a private local variable and return...
Read more >
Properties with Parameters (and Making Them the Default)
You can create properties that accept parameters (just like methods!). But they work best when they're also the default property of your ...
Read more >
VB.NET Property Examples (Get, Set)
In VB.NET, a Property is similar to a Function. With a getter and a setter, it controls access to a value. This value...
Read more >
Re: A Class Public Property with one input parameter
I have a VB.NET code, but I don't know how to write in C#. Code: Public WriteOnly Property Borders(Edge As EdgeEnum) As LineStyleEnum...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found