ContractAnnotation validate property of input variable

Is it possible to validate properties on input attributes?

For example on

public interface IPeriod
{
     DateTime Start {get;set;}
     DateTime? End {get;set;}
}

we have an extension method

public bool IsClosed(this IPeriod period)
{
     return period.HasValue && period.Value != DateTime.MaxValue;
}

is if possible to decorate this method with a ContractAnnotation somwhat like

[ContactAnnotation("=> true,period.End:notnull")]

So Resharper knows that I can use

period.IsClosed() ? Something(....period.End.Value.....) : SomethingElse;

Without resharper giving me a warning.

1 comment
Comment actions Permalink

This isn't possible with the current version of ReSharper. ContractAnnotationAttribute only looks at parameter names, not properties within parameters. It would make a good feature request, though: http://youtrack.jetbrains.com

0

Please sign in to leave a comment.