GU0008
November 24, 2021 ยท View on GitHub
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...")]