Skip to content

Commit be457f2

Browse files
committed
Minor improvements
1 parent fea811c commit be457f2

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,39 @@ To run using [mono](http://www.mono-project.com/download/#download-lin) on Linux
3636
## Modes
3737

3838
#### Mode - Convert
39-
- Converts all [Contract.Requires](https://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contract.requires(v=vs.110).aspx) to "if(!x) throw new ArgumentException()" pattern.
40-
- Converts all [Contract.Assert](https://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contract.assert(v=vs.110).aspx) to [Debug.Assert](https://msdn.microsoft.com/en-us/library/system.diagnostics.debug.assert(v=vs.110).aspx)
41-
- Removes any other [Contract](https://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contract(v=vs.110).aspx) invocations.
42-
- Invariant methods are preserved
43-
- Attributes and Contract classes are removed
39+
- Converts all [Contract.Requires](https://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contract.requires(v=vs.110).aspx) to "if(!x) throw new ArgumentException()" pattern at the beginning of method/property/constructor.
40+
- Converts all [Contract.Ensures](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.contracts.contract.ensures?view=netcore-3.1) to "if(!x) throw new InvalidOperationException()" pattern before each return incide method/property/constructor.
41+
- Converts all [Contract.Assert](https://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contract.assert(v=vs.110).aspx) and [Contract.Assume](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.contracts.contract.assume?view=netcore-3.1) to "if(!x) throw new ArgumentException()" pattern.
42+
- Invokes invariant methods before each return incide method/property/constructor.
43+
- Preserves all other [Contract](https://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contract(v=vs.110).aspx) invocations (including Attributes and Contract classes).
44+
- Removes CodeContract properties and constants from project files
4445

4546
#### Mode - Remove
4647
- Removes any [Contract](https://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contract(v=vs.110).aspx) invocations.
4748
- Invariant methods are preserved
4849
- Attributes and Contract classes are removed
50+
- Removes CodeContract properties and constants from project files
51+
52+
#### Mode - Stats
53+
- Collects statistics about how [Contracts](https://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contract(v=vs.110).aspx) are used. Example of result:
54+
[ContractClassFor] 1
55+
[ContractInvariantMethod] 2
56+
Contract.Assert 1
57+
Contract.Ensures 6
58+
Contract.Invariant 2
59+
Contract.Requires 6
60+
Contract.Result 5
61+
62+
## Annotation modes
63+
64+
In Convert mode [Jet Brains annotations](https://blog.jetbrains.com/dotnet/2018/05/02/improving-rider-resharper-code-analysis-using-jetbrains-annotations/) ([NotNull]) can be added to class members. Jet Brains annotations are added using [JetBrains.Annotations NuGet package](https://www.nuget.org/packages/JetBrains.Annotations/).
65+
66+
#### Mode - None
67+
Don't add annotations
68+
69+
#### Mode - Add
70+
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](https://blog.jetbrains.com/dotnet/2015/08/12/how-to-use-jetbrains-annotations-to-improve-resharper-inspections/).
71+
72+
#### Mode - IncludeIntoBinaries
73+
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](https://blog.jetbrains.com/dotnet/2015/08/12/how-to-use-jetbrains-annotations-to-improve-resharper-inspections/).
74+

src/CodeContractsRemover/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace CodeContractsRemover
99
{
10-
[Description("usage CodeContractsRemover.exe <Convert|Remove> <directoryPath> [--searchPattern *.cs *.csproj] [--encoding utf-8] [--ignorePattern .svn/ ]")]
10+
[Description("usage CodeContractsRemover.exe <Convert|Remove|Stats> [--directoryPath .] [--searchPattern *.cs *.csproj] [--encoding utf-8] [--ignorePattern .svn/] [--annotations Add]")]
1111
public static class Program
1212
{
1313
private static readonly string[] DefaultSearchPattern = new[] { "*.cs", "*.vb", "*.csproj", "*.vbproj" };

src/CodeContractsRemoverTests/CodeContractsRemoverTests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
</Content>
4747
<None Include="ContractRemoverTests.Process_ExtensionsCase_ResultIsCorrect.approved.cs" />
4848
<None Include="ContractRemoverTests.Process_FileWithLeadingComments_LeadingCommentsArePreserved.approved.cs" />
49+
<None Include="ProjectContractRemoverTests.Process_AddAnnotations_CodeContractsRemoved.approved.csproj" />
50+
<None Include="ProjectContractRemoverTests.Process_AddAnnotations_ReferenceToJJAAdded.approved.csproj" />
51+
<None Include="ProjectContractRemoverTests.Process_CsProj_CodeContractsRemoved.approved.csproj" />
52+
<None Include="ProjectContractRemoverTests.Process_IncludeAnnotationsIntoBinaries_ResultIsCorrect.approved.csproj" />
4953
<None Include="TestCases\TestSubject.cs">
5054
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5155
</None>

0 commit comments

Comments
 (0)