{"id":16366594,"url":"https://github.com/lecaillon/preconditions","last_synced_at":"2025-07-29T12:39:22.106Z","repository":{"id":13537835,"uuid":"74703551","full_name":"lecaillon/Preconditions","owner":"lecaillon","description":"Preconditions.NET provides convenience static methods to help check that a method or a constructor is invoked with proper parameter or not.","archived":false,"fork":false,"pushed_at":"2022-02-16T15:27:21.000Z","size":69,"stargazers_count":25,"open_issues_count":2,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-15T11:15:21.702Z","etag":null,"topics":["argument-checks","check","guard","preconditions"],"latest_commit_sha":null,"homepage":"","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/lecaillon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"lecaillon"}},"created_at":"2016-11-24T20:35:21.000Z","updated_at":"2024-09-19T04:26:44.000Z","dependencies_parsed_at":"2022-08-07T07:15:30.179Z","dependency_job_id":null,"html_url":"https://github.com/lecaillon/Preconditions","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lecaillon%2FPreconditions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lecaillon%2FPreconditions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lecaillon%2FPreconditions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lecaillon%2FPreconditions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lecaillon","download_url":"https://codeload.github.com/lecaillon/Preconditions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245047977,"owners_count":20552430,"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":["argument-checks","check","guard","preconditions"],"created_at":"2024-10-11T02:46:59.374Z","updated_at":"2025-03-23T02:32:40.396Z","avatar_url":"https://github.com/lecaillon.png","language":"C#","funding_links":["https://github.com/sponsors/lecaillon"],"categories":[],"sub_categories":[],"readme":"# Preconditions.NET [![AppVeyor build status](https://ci.appveyor.com/api/projects/status/p1qsj8wt27023w0u/branch/master?svg=true)](https://ci.appveyor.com/project/lecaillon/preconditions/branch/master) [![NuGet](https://buildstats.info/nuget/Preconditions.NET)](https://www.nuget.org/packages/Preconditions.NET)\n\u003cimg align=\"right\" width=\"128px\" height=\"128px\" src=\"https://raw.githubusercontent.com/lecaillon/Preconditions/master/logo128.png\"\u003e\n\nPreconditions.NET is a personal, free-time project with no funding. If you use Evolve in your daily work and feel that it makes your life easier, consider supporting its development via [GitHub Sponsors](https://github.com/sponsors/lecaillon) :heart: and by adding a star to this repository :star:\n\n## Introduction\n\nPreconditions.NET provides convenience static methods to help check that a method or a constructor is invoked with proper parameter or not. In other words it checks the *pre-conditions*. The goal of this class is to improve readability of code.\n\nPreconditions.NET returns the tested value on success, allowing to check and call a method at the same time.\n\nOn failure it **always** throws an `ArgumentException`, `ArgumentNullException` or `ArgumentOutOfRangeException`.\n\n## Why Preconditions.NET v2 ?\n\nPreconditions.NET v2.0.0 is a complete rewrite that takes advantage of nullable types, the `NotNull` attribute and the new .NET 6 `CallerArgumentExpression` attribute.\nIt is no more mandatory to pass the parameter name being checked.\n\nIt also adds new methods (cf. [checklist](#the-checklist)) and remove Check.Zero().\n\n## How to use it ?\n\nBecause Preconditions.NET is only one code file, you can either copy the [Check.cs](https://github.com/lecaillon/Preconditions/blob/master/src/Preconditions/Check.cs) class or include the NuGet package to your project :\n```\nPM\u003e Install-Package Preconditions.NET\n```\n\n## Example\n\n```c#\npublic class Employee : Person\n{\n    public Employee(string name, string id) : base(Check.NotNullOrEmpty(name))\n    {\n        Id = Check.NullableButNotEmpty(id);\n    }\n\n    public string Id { get; }\n}\n```\n\n## The checklist\n\n- Check.NotNull(*object*)\n- Check.NullableButNotEmpty (*string*)\n- Check.NotNullOrEmpty(*string*)\n- Check.NotNullOrEmpty(*IEnumerable*)\n- Check.HasNoNulls(*IEnumerable*)\n- Check.NotEmpty(*Guid*)\n- Check.FileExists()\n- Check.DirectoryExists()\n- Check.Positive()\n- Check.PositiveOrNull()\n- Check.Negative()\n- Check.NegativeOrNull()\n- Check.NotNegative()\n- Check.NotNegativeOrNull()\n- Check.True(*Func\u003cbool\u003e*)\n\n## Feedback and issues\nFeedback, improvements, ideas are welcomed.\nFeel free to create new [issues](https://github.com/lecaillon/Preconditions/issues) at the issues section.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flecaillon%2Fpreconditions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flecaillon%2Fpreconditions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flecaillon%2Fpreconditions/lists"}