Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define the default name field suggestion in Visual Studio 2019 for c#

Given the class:

class BaseController
{
    BaseView _baseView;
    BaseModel _baseModel;
}

When using visual studio's suggested naming, it offers me the name base, not baseView. I've managed to add the _ prefix through the options, text-editor, c#, Code Style. But I cannot see how to control the proposed field name suggestion.

I was wondering if this could be controlled so it would suggest _baseView and _baseModel etc.

like image 779
Gregory William Bryant Avatar asked Mar 01 '20 14:03

Gregory William Bryant


1 Answers

This worked for me:

  1. Go to Tools -> Options -> Text Editor -> C# -> Code Style -> Naming
    enter image description here
  2. Click "Select manage styles"
    enter image description here
  3. Click the "+" to add a new naming style

  4. Fill in:
    Naming Style Title: "_camelCase"
    Required Prefix: "_"
    Capitalization: "camel Case Name"
    enter image description here

  5. Select "OK"

  6. Click the "+" to add a new Specification

  7. In the new row select:
    Specification: "Private or Internal Field"
    Required Style: "_camelCase"
    Severity: "Suggestion"
    enter image description here

  8. Restart Visual Studio

That's it!

enter image description here

like image 91
Eliahu Aaron Avatar answered Oct 07 '22 18:10

Eliahu Aaron