CodeContracts:ccrewrite 失败,对象引用未设置到对象的实例
下面的代码让 ccrewrite 爆炸!有想法吗? 顺便说一句,如果您注释掉 ActualClass,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);
}
提前致谢!
The below code makes ccrewrite blow up! Ideas?
BTW, If you comment out the ActualClass, ccrewrite succeeds...
[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);
}
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我没有很好地阅读乔恩·斯基特,这对我来说是对的;)关于重写器如何获取合同并将它们放入您的实际课程中的一些内容......
http://social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/853227bf -56e6-427b-8e9e-162c129e87ce/
Well, serves me right for not reading Jon Skeet well enough ;) The bit about how rewriter takes the contracts and puts them in your actual class...
http://social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/853227bf-56e6-427b-8e9e-162c129e87ce/