मैं कोड अनुबंधों को गलत समझ सकता हूं, लेकिन यहां मेरी स्थिति है। मैं एक अपेक्षाकृत सरल अनुबंध को जोड़ने के लिए कोशिश कर रहा हूँकोड अनुबंध और विरासत की समस्याएं, क्या चलती है?
interface IFetch<T> // defined in another DLL
{
T Fetch(int id);
}
interface IUserFetch : IFetch<User>
{
IEnumerable<User> GetUsersLoggedIn();
}
class UserFetch : IUserFetch
{
public User Fetch(int id)
{
return (User) Database.DoStuff (id);
}
public IEnumerable<User> GetUsersLoggedIn()
{
return (IEnumerable<User>) Database.DoMoreStuff();
}
}
:
मैं निम्नलिखित कोड है Contract.Requires (id != 0);
, और मैं इसे Fetch
पर मान्य चाहते हैं। जब मैं इसे सीधे प्राप्त करने के लिए जोड़ता हूं, तो मुझे चेतावनी मिलती है कि Method Fetch(int id) implements interface 3rdParty.IFetch<User> and thus cannot add Requires
।
मैंने एक अमूर्त कोड अनुबंध क्लास को IFetch लागू करने के लिए बनाया है और इसे ContractClass
और ContractClassFor
विशेषताओं का उपयोग करके उपयोगकर्ताफ़ेच से/पर इंगित किया है। मुझे अभी भी CodeContracts: The class 'FetchUserContracts' is supposed to be a contract class for '3rdParty.IFetch<User>', but that type does not point back to this class.
जैसी त्रुटि मिलती है, हालांकि, तृतीयParty.IFetch एक सामान्य प्रकार है, मुझे नहीं लगता कि मैं इसे विशेष रूप से कोड अनुबंध भी डाल सकता हूं।
क्या समस्या स्पष्ट हो गई है, और यदि हां, तो मैं इसे कैसे हल करूं?
संभावित डुप्लिकेट: http://stackoverflow.com/questions/3414586 –
@RobertHarvey: मैं ज्यादातर कि ले लेंगे, सिवाय मेरी समस्या जेनरिक से अधिक स्टेम करने लगता है –