Delen via


Lokale functie statisch maken (IDE0062)

Eigenschap Waarde
Regel-ID IDE0062
titel Lokale functie statisch maken
categorie Stijl
subcategorie Taalregels (wijzigingsvoorkeuren)
Toepasselijke talen C# 8.0+
opties csharp_prefer_static_local_function

Overzicht

Deze stijlregel betreft de voorkeur om lokale functies al dan niet als static te markeren.

Opties

Met opties geeft u het gedrag op dat door de regel moet worden afgedwongen. Zie Option-indelingvoor meer informatie over het configureren van opties.

csharp_prefer_static_local_function

Eigendom Waarde Beschrijving
Optienaam csharp_prefer_static_local_function
optiewaarden true Geef de voorkeur aan het markeren van lokale functies met static
false Geef de voorkeur aan het markeren van lokale functies boven als static.
standaardoptiewaarde true:suggestion
// csharp_prefer_static_local_function = true
void M()
{
    Hello();
    static void Hello()
    {
        Console.WriteLine("Hello");
    }
}

// csharp_prefer_static_local_function = false
void M()
{
    Hello();
    void Hello()
    {
        Console.WriteLine("Hello");
    }
}

Een waarschuwing onderdrukken

Als u slechts één schending wilt onderdrukken, voegt u preprocessorrichtlijnen toe aan uw bronbestand om de regel uit te schakelen en vervolgens opnieuw in te schakelen.

#pragma warning disable IDE0062
// The code that's violating the rule is on this line.
#pragma warning restore IDE0062

Als u de regel voor een bestand, map of project wilt uitschakelen, stelt u de ernst ervan in op none in het configuratiebestand.

[*.{cs,vb}]
dotnet_diagnostic.IDE0062.severity = none

Als u alle regels voor de codestijl wilt uitschakelen, stelt u de ernst voor de categorie Style in op none in het configuratiebestand.

[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none

Voor meer informatie, zie Hoe codeanalysewaarschuwingen te onderdrukken.

Zie ook