Search code examples
.netcode-contracts

How to express that a method in a library is pure?


Given the case when you need to call a method of a library that you can't modify in a Contract.Requires, (v.g., the method Regex.Matches) there is a way to indicate this method is pure?

 Contract.Requires<ArgumentException>(Regex.Matches(password, "\d").Count > 1)

Warning: Detected call to method 'System.Text.RegularExpressions.Regex.Matches(System.String,System.String)' without [Pure] in contracts of method


Solution

  • Actually this is not possible. Microsoft would decorate the signatures of methods like this to offer a better integration with code contracts.