{"id":31832961,"url":"https://github.com/ikopylov/codecontracts-remover","last_synced_at":"2026-06-16T20:32:19.060Z","repository":{"id":90620973,"uuid":"118280136","full_name":"ikopylov/CodeContracts-remover","owner":"ikopylov","description":"Code Fixes for Roslyn that remove CodeContracts from source code","archived":false,"fork":false,"pushed_at":"2019-10-28T18:32:29.000Z","size":157,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-19T07:52:01.184Z","etag":null,"topics":["codecontracts","csharp","roslyn"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ikopylov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-01-20T20:57:49.000Z","updated_at":"2019-10-28T18:32:31.000Z","dependencies_parsed_at":"2023-03-11T22:31:06.153Z","dependency_job_id":null,"html_url":"https://github.com/ikopylov/CodeContracts-remover","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ikopylov/CodeContracts-remover","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikopylov%2FCodeContracts-remover","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikopylov%2FCodeContracts-remover/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikopylov%2FCodeContracts-remover/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikopylov%2FCodeContracts-remover/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ikopylov","download_url":"https://codeload.github.com/ikopylov/CodeContracts-remover/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikopylov%2FCodeContracts-remover/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34423214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codecontracts","csharp","roslyn"],"created_at":"2025-10-11T23:30:14.183Z","updated_at":"2026-06-16T20:32:19.034Z","avatar_url":"https://github.com/ikopylov.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CodeContracts Remover\r\nThis repository contains Code Fixes for Roslyn that help to remove CodeContracts from source code.\r\n\r\nList of provided analyzers and code fixes (in the order of application):\r\n- __CR01_RetrieveCodeContractFromBase__ - indicates that the ```Contract.Requires``` method can be retrieved from Contract class of from base class;\r\n- __CR02_RequiresGenericToIfThrow__ - indicates that ```Contract.Requires\u003cTException\u003e()``` method should be replaced with _if...throw_ statement;\r\n- __CR03_ContractToDebugAssertReplace__ - indicates that ```Contract.Requires()```, ```Contract.Assert()``` and ```Contract.Assume()``` should be replaced with ```Debug.Assert()```;\r\n- __CR04_EliminateCallsToContractMethods__ - indicates that all other ```Contract``` methods (Ensure, EnsureOnThrow, etc.) should be removed from source code;\r\n- __CR05_EliminateContractClass__ - indicates that Contract class (class that marked with ```ContractClassForAttribute```) can be removed from source code;\r\n- __CR06_EliminateInvariantMethods__ - indicates that Contract invariant method (method marked with ```ContractInvariantMethodAttribute```) can be removed from source code.\r\n\r\n## How to use\r\n\r\nDownload compiled version of library from _binary_ folder or compile it from sources.\r\nAdd ContractRemover.dll as roslyn analyzer to your project.\r\nApply all fixes in the order stated above.\r\n\r\n## Examples\r\n\r\n1. __CR01_RetrieveCodeContractFromBase__\r\n```C#\r\npublic class TestImpl : TestAbstract\r\n{\r\n    public override void Method1(string val)\r\n    {\r\n        throw new NotImplementedException();\r\n    }\r\n}\r\n\r\n[ContractClass(typeof(TestAbstractCC))]\r\npublic abstract class TestAbstract\r\n{\r\n    public abstract void Method1(string val);\r\n}\r\n[ContractClassFor(typeof(TestAbstract))]\r\nabstract class TestAbstractCC : TestAbstract\r\n{\r\n    public override void Method1(string val)\r\n    {\r\n        Contract.Requires(val != null);\r\n        throw new NotImplementedException();\r\n    }\r\n}\r\n```\r\n\r\nwill be translated to\r\n\r\n```C#\r\npublic class TestImpl : TestAbstract\r\n{\r\n    public override void Method1(string val)\r\n    {\r\n        Contract.Requires(val != null);      // This line was extracted from TestAbstractCC\r\n        throw new NotImplementedException();\r\n    }\r\n}\r\n\r\n[ContractClass(typeof(TestAbstractCC))]\r\npublic abstract class TestAbstract\r\n{\r\n    public abstract void Method1(string val);\r\n}\r\n[ContractClassFor(typeof(TestAbstract))]\r\nabstract class TestAbstractCC : TestAbstract\r\n{\r\n    public override void Method1(string val)\r\n    {\r\n        Contract.Requires(val != null);\r\n        throw new NotImplementedException();\r\n    }\r\n}\r\n```\r\n\r\n2. __CR02_RequiresGenericToIfThrow__\r\n```C#\r\nstatic void Method(string val, int data)\r\n{\r\n    Contract.Requires\u003cArgumentNullException\u003e(val != null);\r\n    Contract.Requires\u003cArgumentOutOfRangeException\u003e(data \u003e= 0);\r\n}\r\n```\r\n\r\nwill be translated to\r\n```C#\r\nstatic void Method(string val, int data)\r\n{\r\n    if (val == null)\r\n        throw new ArgumentNullException(nameof(val));\r\n    if (data \u003c 0)\r\n        throw new ArgumentOutOfRangeException(nameof(data), \"data \u003e= 0\");\r\n}\r\n```\r\n\r\n3. __CR03_ContractToDebugAssertReplace__\r\n```C#\r\nstatic void Method(string val, int data)\r\n{\r\n    Contract.Requires(val != null);\r\n    Contract.Assert(data \u003e= 0);\r\n}\r\n```\r\n\r\nwill be translated to\r\n```C#\r\nstatic void Method(string val, int data)\r\n{\r\n    Debug.Assert(val != null, \"val != null\");\r\n    Debug.Assert(data \u003e= 0, \"data \u003e= 0\");\r\n}\r\n```\r\n\r\n4. __CR04_EliminateCallsToContractMethods__\r\n```C#\r\nstatic int Method(string val, int data)\r\n{\r\n    Contract.Ensures(Contract.Result\u003cint\u003e() \u003e 0);\r\n}\r\n```\r\n\r\nwill be translated to\r\n```C#\r\nstatic int Method(string val, int data)\r\n{\r\n}\r\n```\r\n\r\n5. __CR05_EliminateContractClass__\r\n```C#\r\npublic class TestImpl : TestAbstract\r\n{\r\n    public override void Method1(string val)\r\n    {\r\n        Contract.Requires(val != null);\r\n        throw new NotImplementedException();\r\n    }\r\n}\r\n\r\n[ContractClass(typeof(TestAbstractCC))]\r\npublic abstract class TestAbstract\r\n{\r\n    public abstract void Method1(string val);\r\n}\r\n[ContractClassFor(typeof(TestAbstract))]\r\nabstract class TestAbstractCC : TestAbstract\r\n{\r\n    public override void Method1(string val)\r\n    {\r\n        Contract.Requires(val != null);\r\n        throw new NotImplementedException();\r\n    }\r\n}\r\n```\r\n\r\nwill be translated to\r\n\r\n```C#\r\npublic class TestImpl : TestAbstract\r\n{\r\n    public override void Method1(string val)\r\n    {\r\n        Contract.Requires(val != null);\r\n        throw new NotImplementedException();\r\n    }\r\n}\r\n\r\npublic abstract class TestAbstract\r\n{\r\n    public abstract void Method1(string val);\r\n}\r\n```\r\n\r\n\r\n6. __CR06_EliminateInvariantMethods__\r\n```C#\r\npublic class TestImpl : TestAbstract\r\n{\r\n    public string Data { get; set; }\r\n    \r\n    [ContractInvariantMethod]\r\n    private void Invariant()\r\n    {\r\n        Contract.Invariant(Data != null);\r\n    }\t\r\n}\r\n```\r\n\r\nwill be translated to\r\n\r\n```C#\r\npublic class TestImpl : TestAbstract\r\n{\r\n    public string Data { get; set; }\r\n}\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikopylov%2Fcodecontracts-remover","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fikopylov%2Fcodecontracts-remover","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikopylov%2Fcodecontracts-remover/lists"}