Home > Mobile >  Suppress warning when attribute is being used - C# (Unity)
Suppress warning when attribute is being used - C# (Unity)

Time:07-22

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

CodePudding user response:

Rider has [UsedImplicitly] attribute for this.

CodePudding user response:

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
{

}
  • Related