0

I have a private field in a class that is not assigned anywhere explicitly, its value is actually set using reflections and an attribute that goes on the field. Now, Rider, the IDE I use, warns that the field is never assigned. This warning is what I would like to be disabled when the attribute is used. Like what happens with the SerializeField attribute.

I have searched a lot on how to do this, but the problem is that I have no idea where to start or what to search for, so I basically got nowhere. The best lead I got was that I would need to do something related to code analyzers, but I couldn't find out what exactly I need to do to suppress a warning in these conditions.

Warning that I want to disable

How I would like it to be

Lyrca
  • 528
  • 2
  • 15

2 Answers2

4

You should be able to stop the warning by adding the MeansImplicitUseAttribute to your GetComponentAttribute class.

using System;
using JetBrains.Annotations;

[MeansImplicitUse(ImplicitUseKindFlags.Assign)]
public class GetComponentAttribute : Attribute
{

}
Sisus
  • 651
  • 4
  • 8
0

Rider has [UsedImplicitly] attribute for this.

JottoWorol
  • 281
  • 2
  • 9
  • 1
    While this also works it needs to be used on all the fields additionally - [this answer](https://stackoverflow.com/a/73075294/7111561) has to be only done **once** to the attribute itself ;) – derHugo Jul 22 '22 at 09:54
  • Only if you have an access to the attribute code – JottoWorol Jul 24 '22 at 17:46
  • True but in this question this is seems the case ;) If you need to apply it to every field where you need it ... you can as well configure Rider to not warn about those places ... – derHugo Jul 25 '22 at 07:08