You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
bool ICollection.IsSynchronized
{
get
{
return false;
}
}
I get a CC warning:
Warning 12 CodeContracts: Consider adding the postcondition Contract.Ensures(Contract.Result<System.Boolean>() == false); to provide extra-documentation to the library clients
However since this is an interface implementation, I can't add contracts here.
The text was updated successfully, but these errors were encountered:
Adding a post-condition shouldn't be a problem. Did you try adding it? If you're getting another warning or an error then it may be a bug in Code Contracts.
The rule is: You can't add preconditions to inherited members, but you can add post-conditions. See Liskov Substitution Principle.
When I make contract classes (sorry if my assumption is wrong) for interfaces I get around these issues by using abstract override or abstract to signal that I don't want to add a contract for that method or property.
In this case you could probably just do abstract bool ICollection.IsSynchronized { get; } and leave it out of your contract class.
You're right, adding a post condition works in this case. I expected to get the "x is implementing y, thus can't add contracts" warning - so I didn't try.
when implementing an interface method like this:
I get a CC warning:
Warning 12 CodeContracts: Consider adding the postcondition Contract.Ensures(Contract.Result<System.Boolean>() == false); to provide extra-documentation to the library clients
However since this is an interface implementation, I can't add contracts here.
The text was updated successfully, but these errors were encountered: