那麼C#4.0程式碼合同實際上做什麼呢?
閱讀關於System.Diagnostics.Contracts.Contract受靜態類影響的靜態類後,我很高興,並立即開始對Call.Requires()和Contract.Ensures()的呼叫進行編碼.
我想這只是因為我的程式碼是非常棒的,沒有bug的,檢查那些電話實際上做的只是直到最近才出現.一個錯誤滑過來,我意識到這些電話沒有做任何事情!我本來以為他們至少在違反條件時丟擲異常,但沒有這樣的運氣.
我錯過了什麼嗎?有人知道這是什麼意思嗎?
You must use a binary rewriter toinsert run-time enforcement ofcontracts. Otherwise, contracts suchas the Contract.Ensures method canonly be tested statically and will notthrow exceptions during run time if acontract is violated. You can downloadthe binary rewriter CCRewrite fromCode Contracts on the MSDN DevLabs Website. CCRewrite comes with a VisualStudio add-in that enables you toactivate run-time contract enforcementfrom the project Properties page. Thebinary rewriter and the Visual Studioadd-in do not ship with Visual Studio2010 or the Windows SDK.
http://stackoverflow.com/questions/2883717/so-do-c4-0-code-contracts-actually-do-anything