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
 C# ListMethodsInCurrentFile and primary ctor
 New Topic  Reply to Topic
 Printer Friendly
Author  Topic Next Topic  

azur
Ketchup Master

Germany
62 Posts

Posted - Sep 12 2025 :  09:27:37 AM  Show Profile  Reply with Quote

public class X {
  private readonly string _name = string.Empty;

  public X(string? name)
  {
    _name = name ?? string.Empty;
  }
  public bool IsValid()
  {
    return !string.IsNullOrEmpty(_name);
  }
}


ListMethodsInCurrentFile show me "X, X.IsValid, X.X(string? name)"

When I use C# with TargetFrameWork net9.0, I got IDE0290 'Use primary constructor'.

If I follow the suggestion then the code looks like this.


public class X(string? name) {

 private readonly string _name = name ?? string.Empty;

 public bool IsValid()
 {
   return !string.IsNullOrEmpty(_name);
 }
}

ListMethodsInCurrentFile then only show me "X(string? name)"

feline
Whole Tomato Software

United Kingdom
19211 Posts

Posted - Sep 15 2025 :  06:59:52 AM  Show Profile  Reply with Quote
Thank you for the clear description. Unfortunately VA doesn't currently support C# primary constructors, but this is something that is on our list of things to fix:

case=165542

One user who ran into this reported adding the following to suppress the prompt for now:

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0290:Use primary constructor", Justification = "Otherwise Visual Assist will not recognize the members.")]


If you have a moment you might want to report this via email to [email protected] since the new reports that get run to track interest in, and problems with open cases only pick up things reported via email, not posted here to the forum. So that would give this case a bit more weight.

zen is the art of being at one with the two'ness

Edited by - feline on Sep 15 2025 07:05:24 AM
Go to Top of Page

azur
Ketchup Master

Germany
62 Posts

Posted - Sep 16 2025 :  08:28:38 AM  Show Profile  Reply with Quote
I sent an email to support.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19211 Posts

Posted - Sep 16 2025 :  10:24:16 AM  Show Profile  Reply with Quote
Azur thank you for that.

For anyone else who ends up here, I have found a better approach than editing the source code.

Open Solution Explorer
Right click on the project in the solution.
Add -> New Item...
If you get the small dialog just asking for a filename use the "Show All Templates" button
Under "C# Items" select "editorconfig File (empty)"
In the editor for the .editconfig file go to the "Code Style" page and filter on "primary constructor" and toggle the Value column to "No"

zen is the art of being at one with the two'ness
Go to Top of Page
   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