1
以下代碼使ccrewrite炸燬!想法? 順便說一句,如果你註釋掉ActualClass,ccrewrite成功...CodeContracts:ccrewrite失敗,對象引用未設置爲對象的實例
[ContractClass(typeof(TestContracts))]
interface ITestInterface
{
bool IsStarted { get; set; }
void Begin();
}
class ActualClass : ITestInterface
{
public bool IsStarted { get; set; }
public void Begin()
{
this.IsStarted = true;
}
}
[ContractClassFor(typeof(ITestInterface))]
class TestContracts : ITestInterface
{
ITestInterface Current { get; set; }
private TestContracts()
{
Current = this;
}
#region ITestInterface Members
bool ITestInterface.IsStarted
{
get; set;
}
void ITestInterface.Begin()
{
Contract.Requires(!Current.IsStarted);
Contract.Ensures(Current.IsStarted);
}
提前感謝!