Is it possible to extend resharper code inspection/annotations to handle cases you know staticly are correct?
For example, I have utility function I know satisfy certain conditions, such as:
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 a nullable has a value, and I'd like the "Possible System.InvalidOperationException" inspection not to fire for something like:
if (Utils.IsValid(nullableValue))
{
DoSomethingWith(nullableValue.Value);
}
Sure I could suppress the inspection/etc, but is it possible to extend the static typing to indicate that this would actually ensure the value is non-nullable?
(I suppose a related but overly general question is should I be using another static typing check instead of resharper that might handle it, but I won't ask for fear of being overly broad!)
ReSharper helps you resolve most of the discovered code issues automatically. All you need is to press Alt+Enter when the caret is on a code issue highlighted in the editor and check the suggested quick-fixes.
Syntax highlightingReSharper extends the default Visual Studio's symbol highlighting. Additionally, it highlights fields, local variables, types, and other identifier with configurable colors. For example, ReSharper syntax highlighting allows you to easily distinguish between local variables and fields in your code.
To configure the main set of ReSharper preferencesIn the Visual Studio menu, choose ReSharper | Options. In the Options dialog that appears, select a node in the left pane and configure settings in the right pane. Use the search box in the left top corner to find a specific preference.
Per Daniel's suggestion, resharper supports a good deal of annotations to assist with inspection.
Specifically, via the documentation what we're looking for here is something like:
[ContractAnnotation("d:null => false")]
static public bool IsValid(double? d)
{
return d != null && IsValid(d.Value);
}
Which does the trick perfectly, and the static check works beautifully.
Love that resharper!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With