{"id":25979239,"url":"https://github.com/bjorg/argumentassert","last_synced_at":"2025-03-05T06:28:59.644Z","repository":{"id":43873894,"uuid":"459359952","full_name":"bjorg/ArgumentAssert","owner":"bjorg","description":"Assert argument values and throw descriptive exceptions","archived":false,"fork":false,"pushed_at":"2023-09-23T07:12:59.000Z","size":16,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-24T07:09:26.476Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bjorg.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}},"created_at":"2022-02-14T23:31:01.000Z","updated_at":"2023-06-25T14:00:38.000Z","dependencies_parsed_at":"2022-09-25T00:03:12.369Z","dependency_job_id":null,"html_url":"https://github.com/bjorg/ArgumentAssert","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FArgumentAssert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FArgumentAssert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FArgumentAssert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FArgumentAssert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjorg","download_url":"https://codeload.github.com/bjorg/ArgumentAssert/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241978475,"owners_count":20051984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-03-05T06:28:59.065Z","updated_at":"2025-03-05T06:28:59.632Z","avatar_url":"https://github.com/bjorg.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ArgumentAssert\n\n`ArgumentAssert` is a library that simplifies asserting conditions on arguments. If the condition is not met, an `ArgumentAssertException` is thrown with a description of the failed check. In addition, the `Assert()` method informs code-analysis that the check must have been true if execution continues.\n\nRun the `dotnet` command from your project folder to add the `ArgumentAssert` package:\n```\ndotnet add package ArgumentAssert\n```\n\n## Sample: Assertion throws exception\n\nThe following code asserts the `value` argument is within the expected range or throws an `ArgumentAssertException` exception.\n```csharp\nint AssertValueIsInRange(int value) {\n    ArgumentAssertException.Assert(value is \u003e 0 and \u003c 10);\n    return value;\n}\n```\n\nWhen the assertion fails, the exception message shows the failed expression.\n```\nUnhandled exception. System.ArgumentAssertException: value is \u003e 0 and \u003c 10\n```\n\n## Sample: Assertion informs code analysis\n\nThe following code asserts the `value` argument is not null and has a length between 1 to 9 characters. Code analysis knows that the pattern is true when `Assert()` returns successfully. Therefore, there is no warning for the `return` statement.\n```csharp\nstring AssertValueIsNotNull(string? value) {\n    ArgumentAssertException.Assert(value is { Length: \u003e 0 and \u003c 10 });\n\n    // no warning on the following line\n    return value.ToUpper();\n}\n```\n\nWhen the assertion fails, the exception message shows the failed expression.\n```\nUnhandled exception. System.ArgumentAssertException: value is { Length: \u003e 0 and \u003c 10 }\n```\n\n## Sample: Streamline calls to Assert()\n\nThe following code uses the `using static` statement to expose the `Assert()` method without requiring the class name. This approach streamlines the code when many assertions are being performed throughout the codebase.\n```csharp\nusing static System.ArgumentAssertException;\n\nint AssertValueIsInRange(int value) {\n    Assert(value is \u003e 0 and \u003c 10);\n    return value;\n}\n```\n\n\n## License\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjorg%2Fargumentassert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjorg%2Fargumentassert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjorg%2Fargumentassert/lists"}