Udostępnij za pośrednictwem


Avoid uncalled private code

TypeName

AvoidUncalledPrivateCode

CheckId

CA1811

Category

Microsoft.Performance

Breaking Change

Non Breaking

Cause

A private or internal (assembly-level) member does not have callers in the assembly, is not invoked by the common language runtime, and the member is not invoked by a delegate. The following members are not checked by this rule:

Rule Description

This rule can report false positives if there are entry points that are not currently identified by the rule logic. Also, it is possible that a compiler can emit non-callable code into an assembly.

How to Fix Violations

To fix a violation of this rule, remove the non-callable code, or add code that calls it.

When to Suppress Warnings

It is safe to suppress a warning from this rule.

Avoid uninstantiated internal classes

Review unused parameters

Remove unused locals

Example

This rule will report a false positive if a member is called in a preprocessor if# region.

using System;

namespace SampleNamespace
{    
    class SampleClass    
    {        
        static void Main()
        {
        }

        public void NotifyByEMail(string to) 
        {
            // ...
        }

        public void AnotherMethod() 
        {
            #if !DEBUG
                NotifyByEMail("this.that@someplace.com");
            #endif
        }
    }
}