CodeContractsRemover 1.0.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package CodeContractsRemover --version 1.0.8                
NuGet\Install-Package CodeContractsRemover -Version 1.0.8                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CodeContractsRemover" Version="1.0.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CodeContractsRemover --version 1.0.8                
#r "nuget: CodeContractsRemover, 1.0.8"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CodeContractsRemover as a Cake Addin
#addin nuget:?package=CodeContractsRemover&version=1.0.8

// Install CodeContractsRemover as a Cake Tool
#tool nuget:?package=CodeContractsRemover&version=1.0.8                

Introduction

Tool for removing .NET Code Contracts from source code. Currently only C# is supported. I will gladly accept PR with VB support.

.NET 4.7.1 is required to run this application.

Installation

Install-Package CodeContractsRemover

or

Download and un-zip from https://www.nuget.org/api/v2/package/CodeContractsRemover 

Usage

Tool is located at "PROJECT_DIR/packages/CodeContractsRemover.VERSION/tools/".

CodeContractsRemover.exe <Convert|Stats> <directoryPath> [--searchPattern *.cs *.csproj] [--encoding utf-8] [--ignorePattern .svn/ ]

Example

CodeContractsRemover.exe Convert ./myproject

To run using mono on Mac OS X

/Library/Frameworks/Mono.framework/Commands/mono code_contracts_remover.exe Convert ./myproject

To run using mono on Linux

/usr/bin/mono code_contracts_remover.exe Convert ./myproject

Modes

Mode - Convert
  • Converts all Contract.Requires to "if(!x) throw new ArgumentException()" pattern at the beginning of method/property/constructor.
  • Converts all Contract.Ensures to "if(!x) throw new InvalidOperationException()" pattern before each return incide method/property/constructor.
  • Converts all Contract.Assert and Contract.Assume to "if(!x) throw new ArgumentException()" pattern.
  • Invokes invariant methods before each return incide method/property/constructor.
  • Preserves all other Contract invocations (including Attributes and Contract classes).
  • Removes CodeContract properties and constants from project files

#### Mode - Remove

  • Removes any Contract invocations.
  • Invariant methods are preserved
  • Attributes and Contract classes are removed
  • Removes CodeContract properties and constants from project files
Mode - Stats
  • Collects statistics about how Contracts are used. Example of result:
[ContractClassFor]                                	  1
[ContractInvariantMethod]                         	  2
Contract.Assert                                   	  1
Contract.Ensures                                  	  6
Contract.Invariant                                	  2
Contract.Requires                                 	  6
Contract.Result                                   	  5

Annotation modes

In Convert mode Jet Brains annotations ([NotNull]) can be added to class members. Jet Brains annotations are added using JetBrains.Annotations NuGet package.

Mode - None

Don't add annotations

Mode - Add

Include annotations only for work in Visual Studio/Rider before compilation. When project is compiled, annotations would be removed. When dll is referenced into other project, Rider/Re# wouldn't show hints. This mode is recommended for applications. Read more on Jet Brains site.

Mode - IncludeIntoBinaries

Annotations will be included into binaries, so Rider/Re# would show hints before and after compilation (when binary is referenced into other project). This mode is recommended for packages. Read more on Jet Brains site.

Contributors

  • @ishatalkin
  • @mgaffigan
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.9 1,904 11/28/2020
1.0.8 1,985 9/29/2020
1.0.7 2,205 5/14/2019
1.0.6 1,986 5/8/2019
1.0.5 5,863 3/28/2017