tailieunhanh - Lập trình .net 4.0 và visual studio 2010 part 14
Mã số hợp đồng là một phương pháp thể hiện hạn chế và giả định trong mã của bạn. Chúng cho phép đặc tả các quy tắc phức tạp có thể được xác nhận ở cả hai lập thời gian và thời gian chạy. Mã số hợp đồng cũng được hỗ trợ trong VS2008. | CHAPTER 4 CLR AND BCL CHANGES Code Contracts Code contracts are a method for expressing constraints and assumptions within your code. They allow specification of complex rules that can be validated at both compile time and runtime. Code contracts are also supported in VS2008. NOTE Compile time or static verification is available only in the Premium Ultimate editions of Visual Studio. This is a real shame because it will probably prevent widespread adoption of this great technology rather than encouraging users to purchase a more expensive edition of Visual Studio similar to MSTest VS2005 . Hopefully this is not permanent and you will see static verification available in all future versions of Visual Studio. In addition to providing validation code contracts can assist with code documentation and aiding understanding of a problem. Functionality is available to automatically remove contracts from production code and separate them into a separate assembly if third parties want to use them. Code contracts are part of Microsoft s ongoing research project Spec Spec s developers say they have been influenced by the Eiffel JML and AsmL languages. CAUTION Code contracts are still in active development so this functionality might change. Hello Code Contracts To ensure that values are not null you have probably written code similar to the following many times public void myFunction string input if input null throw new Input cannot be null Or perhaps you utilized the debug or trace assert like so input null Code contracts are superior to the previous methods because they do the following Allow the creation of more complex rules Can help you write better code by getting you to think about constraints within your code Can reduce prevent side effects 88 CHAPTER 4 CLR AND BCL CHANGES Can be validated at both compile time and runtime Are easy to read Can be interpreted by automated tools such as PEX http en-us .
đang nạp các trang xem trước