I'm implementing a class which implements IDictionary. But I'm not able to match the code contract for TryGetValue.
Here's the relevant part of the code:
class Wrapper : IDictionary<string, object>
{
...
IDictionary<string,object> dictionary;
public bool TryGetValue(string key, out object value)
{
var result = dictionary.TryGetValue(key, out value);
Contract.Assume(result == ContainsKey(key));
return result;
}
public bool ContainsKey(string key)
{
Contract.Ensures(Contract.Result<bool>() == dictionary.ContainsKey(key));
return dictionary.ContainsKey(key);
}
...
}
The static analysis complains about:
CodeContracts: ensures unproven:
Contract.Result<bool>() == @this.ContainsKey(key)
What should I do to meet the contract requirements?
Remarks:
The problem doesn't appear, when the key is generic (like Wrapper<TKey> : IDictionary<TKey, object>
).