मुझे यकीन है कि अगर मैं गलत यहाँ या अगर यह समस्या दूर करनी होगी कुछ कर रहा हूँ नहीं कर रहा हूँ ...कोड संविदा: यह सुनिश्चित Unproven और आवश्यक Unproven
मैं एक कस्टम शब्दकोश आवरण वर्ग है और यहाँ एक टुकड़ा है आवश्यक कोड का।
public int Count
{
get
{
Contract.Ensures(Contract.Result<int>() >= 0);
return InternalDictionary.Count;
}
}
public bool ContainsKey(TKey key)
{
//This contract was suggested by the warning message, if I remove it
//I still get the same warning...
Contract.Ensures(!Contract.Result<bool>() || Count > 0);
return InternalDictionary.ContainsKey(key);
}
एकमात्र कारण मैं ContainsKey के लिए लाइन जोड़ा है, क्योंकि मैं निम्न चेतावनी संदेश मिल गया (और अब भी करते हैं): Codecontracts: ensures unproven: !Contract.Result<bool>() || @this.Count > 0
। मैं इस लाइन को हटा सकता हूं और अभी भी समान ISSUE प्राप्त कर सकता हूं!
इन मुद्दों से छुटकारा पाने के लिए मैं यहां क्या करूँ?
अद्यतन:
मैं भी (के रूप में सुझाव दिया) की कोशिश की ...
public Boolean ContainsKey(TKey key)
{
Contract.Requires(Count == 0 || InternalDictionary.ContainsKey(key));
Contract.Ensures(!Contract.Result<bool>() || Count > 0);
return InternalDictionary.ContainsKey(key);
}
चेतावनी 5 विधि 'My.Collections.Generic.ReadOnlyDictionary
2.ContainsKey(type parameter.TKey)' implements interface method 'System.Collections.Generic.IDictionary
2.ContainsKey (प्रकार पैरामीटर.TKey) ', इस प्रकार जोड़ना आवश्यक नहीं है।
ध्यान दें कि आपकी समस्या की जड़ यह है कि यह विधि यह वादा कर रही है कि प्रत्येक कुंजी मिल जाएगी, और इसका वास्तव में कोई नियंत्रण नहीं है। –