Skip to content

Latest commit

 

History

History
74 lines (56 loc) · 1.45 KB

GU0010.md

File metadata and controls

74 lines (56 loc) · 1.45 KB

GU0010

Assigning same value

Topic Value
Id GU0010
Severity Error
Enabled True
Category Gu.Analyzers.Correctness
Code SimpleAssignmentAnalyzer

Description

Assigning same value does not make sense and is sign of a bug.

Motivation

While not a common bug this happens:

public class Foo
{
    public Foo(int a)
    {
        this.A = A;
    }

    public int A { get; private set; }
}

How to fix violations

You probably meant:

public class Foo
{
    public Foo(int a)
    {
        this.A = a;
    }

    public int A { get; private set; }
}

Configure severity

Via ruleset file.

Configure the severity per project, for more info see MSDN.

Via #pragma directive.

#pragma warning disable GU0010 // Assigning same value
Code violating the rule here
#pragma warning restore GU0010 // Assigning same value

Or put this at the top of the file to disable all instances.

#pragma warning disable GU0010 // Assigning same value

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 
    "GU0010:Assigning same value", 
    Justification = "Reason...")]