Context:
The environment I work in has a lot of 'magic' methods and fields that are called or set through reflection from external code. Something may have an attribute that means it will be set to a non-default value, but Visual Studio still doesn't see that aspect and "helpfully" provides the warning.
Since these are handled using attributes and specifically named methods, ideally I'd like to provide VS with additional information so that it knows that it's called or set, without me having to manually suppress each warning.
I've looked into writing a Roslyn analyzer, but from what I can tell I can only add additional warnings, not modify existing warnings/reference count.
Examples:
[MyCmpGet] private Component comp
"Field is never assigned to and will always have its default value null"
However the field is assigned through reflection due to the annotation.
[HarmonyPatch]
class Patch
{
static void Postfix() {}
}
"Private member is unused"
"0 references"
However the method is called through reflection, due to the annotation on the class, and the method having a specific name.
Question:
What is the best way to let visual studio know that these fields are being set, and that these methods are being referenced? Preferably without requiring me to take manual actions for each one, and without adding anything additional to the example code.
Aucun commentaire:
Enregistrer un commentaire