如果codeContracts取代常规ArgumentExceptions?常规、codeContracts、ArgumentExceptions

2023-09-05 01:59:33 作者:爱你。我活该如此°

我可以开始使用,而不是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合同