本文介绍了如果codeContracts取代常规ArgumentExceptions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以开始使用,而不是codeContracts:

Could I start using CodeContracts instead of:

if (XXX == Y)
    throw new ArgumentException("bla bla");

如果我开发一个库是如何工作的,我的图书馆用户不使用codeContracts?

How does it work if I develop a library and my library users do not use CodeContracts?

推荐答案

假设code。使用通过二进制重写运行code合同,它会抛出类似$ C $例外c您发布。重新作家穿过code和替代合同code与参数检查等,这有点像面向方面的编程。它注入code处理情况为你,你已经编译后。

Assuming that the code using code contracts is run through the binary rewriter, it will throw exceptions like code you posted. The re-writer goes through the code and replaces the contract code with argument checking etc. It's kinda like aspect oriented programming. It injects code to handle situations for you after you've compiled it.

如果他们不使用code合同,他们不会得到其静态分析进行,其目的是看看合同,警告他们的利益,他们可能会根据合同的错误和他们的code。

If they don't use Code Contracts they will not get the benefit of having static analysis performed which is designed to look at the contract and warn them they might get an error based on the contract and their code.

code合同

这篇关于如果codeContracts取代常规ArgumentExceptions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:16