Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Navigation Bar doesn't support primary constructor
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ocrosoft
New Member

3 Posts

Posted - Feb 17 2025 :  9:56:55 PM  Show Profile  Reply with Quote

public class TestClassWithClassicConstructor
{
    private int x;
    private int y;
    public TestClassWithClassicConstructor(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
    public int Add()
    {
        return x + y;
    }
}

The above code can normally display the Add method in the dropdown.
After converting the constructor to a primary constructor:

public class TestClassWithPrimaryConstructor(int x, int y)
{
    public int Add()
    {
        return x + y;
    }
}




It seems that VA recognizes the primary constructor as a method instead of recognizing it as a class?


Edited by - ocrosoft on Feb 17 2025 9:59:17 PM

feline
Whole Tomato Software

United Kingdom
19110 Posts

Posted - Feb 18 2025 :  08:07:09 AM  Show Profile  Reply with Quote
I don't understand why you could get this Alt-M list with this code. That isn't what I get. I have attached a screen shot of what I am seeing.

Which IDE and version of VA are you using?

What does VA Outline show? I have also attached what I am seeing there.

Your screen shot suggests there is other code at work that is confusing our parser somehow.







zen is the art of being at one with the two'ness
Go to Top of Page

ocrosoft
New Member

3 Posts

Posted - Feb 18 2025 :  11:01:39 AM  Show Profile  Reply with Quote
This is the full code of my screenshot, please note the class TestClassWithPrimaryConstructor.

namespace ConsoleApp1
{
    public class TestClassWithClassicConstructor
    {
        private int x;
        private int y;
        public TestClassWithClassicConstructor(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
        public int Add()
        {
            return x + y;
        }
    }

    public class TestClassWithPrimaryConstructor(int x, int y)
    {
        public int Add()
        {
            return x + y;
        }
    }
}

Edited by - ocrosoft on Feb 18 2025 11:08:17 AM
Go to Top of Page

ocrosoft
New Member

3 Posts

Posted - Feb 18 2025 :  9:38:02 PM  Show Profile  Reply with Quote
quote:
Originally posted by ocrosoft


public class TestClassWithClassicConstructor
{
    private int x;
    private int y;
    public TestClassWithClassicConstructor(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
    public int Add()
    {
        return x + y;
    }
}

The above code can normally display the Add method in the dropdown.
After converting the constructor to a primary constructor:

public class TestClassWithPrimaryConstructor(int x, int y)
{
    public int Add()
    {
        return x + y;
    }
}




It seems that VA recognizes the primary constructor as a method instead of recognizing it as a class?





Visual studio 2022 preview + VA 2024.12.27 + .NET9

Screenshot with VA outline:


Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19110 Posts

Posted - Feb 19 2025 :  12:22:17 PM  Show Profile  Reply with Quote
OK, I understand what is going on now. A primary constructor is a new feature in C# 12, which VA doesn't understand yet. I have put in a feature request to support this:

case=165542

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000