I'm currently maintaining a legacy project with tens of thousands of existing code. Since there are tons of code that happily assumes every single caller is a well-behaved citizen and just skips validating any data passed to it, I'm introducing Fody NullGuard to keep any new code I write/refactor from following this tradition. Since the code coverage is still scarce in this project, I can't use Implicit validation everywhere, 'cause there could be some, er, "legit" uses of nulls in the code. So, instead, I'm applying the NullGuard attribute only to the new classes I write, or those I can verify won't be negatively affected.
I have a struct whose constructor takes a string as a parameter:
public struct Foo {
public Foo(decimal value, string tag) { ... }
}
I'd like to use Fody to provide safeguards against nulls. However, when I try to place the NullGuard attribute on top of it, I get a compilation error:
using NullGuard;
[NullGuard(ValidationFlags.AllPublicArguments)]
public struct Foo {
public Foo(decimal value, string tag) { ... }
}
error CS0592: Attribute 'NullGuard' is not valid on this declaration type. It is only valid on 'assembly, class' declarations.
Is there any reason why value types are not supported by NullGuard, or is it simply an unfortunate omission (unlikely I think, since it's already in version 6.0)?
Is there any alternative, besides placing manual checks everywhere?