Skip to content

Latest commit

 

History

History
65 lines (48 loc) · 1.47 KB

GU0008.md

File metadata and controls

65 lines (48 loc) · 1.47 KB

GU0008

Avoid relay properties

Topic Value
Id GU0008
Severity Hidden
Enabled False
Category Gu.Analyzers.Correctness
Code PropertyDeclarationAnalyzer

Description

Avoid relay properties.

Motivation

This is just a refactoring aid and disabled by default. Relay properties can be a sign of service locator complicating the graph. Example:

public class Foo
{
    private readonly Bar bar;

    public Foo()
    {
        this.bar = new Bar();
    }

    public int Value => this.bar.Value;
}

How to fix violations

Where appropriate inject Bar where it is needed.

Configure severity

Via ruleset file.

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

Via #pragma directive.

#pragma warning disable GU0008 // Avoid relay properties
Code violating the rule here
#pragma warning restore GU0008 // Avoid relay properties

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

#pragma warning disable GU0008 // Avoid relay properties

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 
    "GU0008:Avoid relay properties", 
    Justification = "Reason...")]