I have a couple of classes that have fields that are only assigned or used through reflection. As a result, the fields lead to the following warnings:
CS0169: The field [...] is never used
CS0649: Field [...] is never assigned to, and will always have its default value 0
A solution would be, to use the SuppressMessageAttribute on all of these classes, but this seems unclean, as the relevant classes already have a custom attribute.
I'd prefer something like this:
[KeepMyFields]
class SomeClass
{
int usedField;
}
class KeepMyFieldsAttribute : System.Diagnostics.CodeAnalysis.SuppressMessageAttribute
{
// [...]
}
However, SuppressMessageAttribute is sealed. What other options do I have, other than adding a code snippet to each relevant class? Might a custom MSBuild task be suitable, or is there a simpler way?