Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

301
Vistas
How to change the code generation style in Visual Studio 2022 to use "_" instead of "this."?

I am using Visual Studio 2022 to write C# code.

When adding a property to the constructor, then click on "Quick action and refactoring" and select "create and assign field for 'session'" visual studio would create the following

public class ExampleClass
{
    private ISession session;

    public ExampleClass(ISession session)
    {
        this.session = session;
    }
}

How can I change that style to use _ instead of this.? so the generated code will then be

public class ExampleClass
{
    private readonly ISession _session;

    public ExampleClass(ISession session)
    {
        _session = session;
    }
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can create a .editorconfig file, which specifies your code style preferences. The VS code generation will then respect that.

See this doc page for a run-down on how to create code style rules.

To enforce that all private fields must be camel-case with a leading underscore, try something like:

dotnet_naming_style.camel_case_leading_underscore.capitalization = camel_case
dotnet_naming_style.camel_case_leading_underscore.required_prefix = _

dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

dotnet_naming_rule.private_fields_should_be_camel_case_leading_underscore.severity = warning
dotnet_naming_rule.private_fields_should_be_camel_case_leading_underscore.symbols = private_fields
dotnet_naming_rule.private_fields_should_be_camel_case_leading_underscore.style = camel_case_leading_underscore

You'll now get a warning if any private fields aren't in this style, and the code generation will also respect this:

Screenshot showing VS respecting this rule

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda