Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if ContractContractValidator doesn't have a validation logic #12

Open
SergeyTeplyakov opened this issue Jul 11, 2014 · 0 comments
Open
Assignees
Labels
Milestone

Comments

@SergeyTeplyakov
Copy link
Owner

Contract validation method marked with ContractArgumentValidator should follow few rules:

  1. Guard method should has a if-throw
  2. if-throw should follow Contract.EndContractBlock

So following code will emit the warning:

using System.Diagnostics.Contracts;
public static class ContractValidator
{
    [ContractArgumentValidator]
    public static void Guard(bool condition)
    {
      // warning CC1053: No validation code recognized in contract argument 
      // validator 'ContractValidator.Guard(System.Boolean)'.
      // if (!condition)
        throw new Exception();
      Contract.EndContractBlock();
    }
}

The same warning would be emitted if uncomment if-condition and comment out Contract.EndContractBlock().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant