ReSharper Code Validation Additions

Is it possible to extend the verification / annotations of the configuration change code to correctly verify cases when you know that they are correct?

For example, I have a utility function that I know that satisfies certain conditions, for example:

static public bool IsValid(double? d) { return d != null && IsValid(d.Value); } static public bool IsValid(double d) { return !Double.IsNaN(d) && !Double.IsInfinity(d); } 

So, this ensures that the nullable value is relevant, and I would like to see the “Possible System.InvalidOperationException” check not work for something like:

  if (Utils.IsValid(nullableValue)) { DoSomethingWith(nullableValue.Value); } 

Of course, I could turn off the / etc check, but can I extend the static typing to indicate that it would actually ensure that the value is not null?

(I believe that a related but too general question is that I should use a different static input check instead of a resharper that could handle it, but I will not ask to be afraid to be too wide!)

+4
source share
1 answer

Under Daniel's assumption, resharper supports a large number of annotations to help with validation.

In particular, through the documentation , what we are looking for here is something like:

  [ContractAnnotation("d:null => false")] static public bool IsValid(double? d) { return d != null && IsValid(d.Value); } 

Which makes the trick great, and static checking works beautifully.

Love that is being decided!

+4
source

All Articles