{"id":25835966,"url":"https://github.com/revazashvili/forbid","last_synced_at":"2025-03-01T01:38:45.045Z","repository":{"id":47099968,"uuid":"406050456","full_name":"Revazashvili/Forbid","owner":"Revazashvili","description":"A simple package with extension methods to forbid some value matches,logical values or ranges in .Net","archived":false,"fork":false,"pushed_at":"2023-04-16T06:07:08.000Z","size":136,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T12:41:29.925Z","etag":null,"topics":["clause","empty","exception","extension","forbid","null"],"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/Revazashvili.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":{"ko_fi":"revazashvili","custom":"buymeacoffee.com/revazashvili"}},"created_at":"2021-09-13T16:36:04.000Z","updated_at":"2023-02-19T09:44:41.000Z","dependencies_parsed_at":"2022-09-18T04:10:38.292Z","dependency_job_id":null,"html_url":"https://github.com/Revazashvili/Forbid","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/Revazashvili%2FForbid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revazashvili%2FForbid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revazashvili%2FForbid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revazashvili%2FForbid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Revazashvili","download_url":"https://codeload.github.com/Revazashvili/Forbid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241304302,"owners_count":19941100,"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":["clause","empty","exception","extension","forbid","null"],"created_at":"2025-03-01T01:38:44.422Z","updated_at":"2025-03-01T01:38:45.036Z","avatar_url":"https://github.com/Revazashvili.png","language":"C#","funding_links":["https://ko-fi.com/revazashvili","buymeacoffee.com/revazashvili"],"categories":[],"sub_categories":[],"readme":"# Forbid\nA simple package with extension methods to forbid some value matches,logical values or ranges in .Net\n\n[![.NET](https://img.shields.io/badge/--512BD4?logo=.net\u0026logoColor=ffffff)](https://dotnet.microsoft.com/)\n![Nuget](https://img.shields.io/nuget/dt/Forbid?color=blue)\n[![NuGet stable version](https://badgen.net/nuget/v/Forbid)](https://www.nuget.org/packages/Forbid)\n[![GitHub license](https://badgen.net/github/license/Revazashvili/Forbid)](https://github.com/Revazashvili/Forbid/blob/main/LICENSE)\n\n\n\n## Give a Star! :star:\nIf you like or are using this project please give it a star. Thanks!\n\n## Installing\nUsing dotnet cli\n```\ndotnet add package Forbid --version 1.0.5\n```\nor package reference\n```\n\u003cPackageReference Include=\"Forbid\" Version=\"1.0.5\" /\u003e\n```\n\n## Supported Methods\n* Null (throws if input is null.)\n* NullOrEmpty (throws if string,guid or IEnumerable\u003cT\u003e is null or empty.)\n* NullOrWhitespace (throws if string input is null, empty or whitespace.)\n* Zero (throws if number input is zero.)\n* True (throws if boolean input is true.)\n* False (throws if boolean input is false.)\n* Range (throws if input is in provided range.)\n* Equal (throws if input is equal to provided value.)\n* NotEqual (throws if input is not equal to provided value.)\n* Positive (throws if input is positive number.)\n* PositiveOrZero (throws if input is positive number or zero.)\n* Negative (throws if input is negative number.)\n* NegativeOrZero (throws if input is negative number or zero.)\n* MoreThan (throws if input is more than provided value.)\n* MoreThanOrEqual (throws if input is more than or equal to provided value.)\n* LessThan (throws if input is less than provided value.)\n* LessThanOrEqual (throws if input is less than or equal to provided value.)\n* Any(throws if any element in input satisfies a condition.)\n* Count(throws if input count equals passed count.)\n* Length(throws if input string length equals passed length.)\n\nYou can pass message or custom exception to methods. \n\n## Usage\n\n```c#\npublic class TestClass\n{\n    private readonly ITestService _testService;\n    private readonly int _someValue;\n        \n    public TestClass(ITestService testService,int someValue)\n    {\n        _testService = Forbid.From.Null(_testService);\n        _someValue = Forbid.From.NegativeOrZero(someValue);\n    }\n}\n```\nOr\n```c#\npublic class TestClassWithCustomMessageOrException\n{\n    private readonly ITestService _testService;\n    private readonly int _someValue;\n        \n    public TestClassWithCustomMessageOrException(ITestService testService,int someValue)\n    {\n        _testService = Forbid.From.Null(_testService,\"test service must not be null.\");\n        _someValue = Forbid.From.NegativeOrZero(someValue,new CustomException());\n    }\n}\n```\nOr you can inject service in DI Container and use IForbid interface.\nfor this install nuget package [Forbid.Extensions.Microsoft.DependencyInjection](https://www.nuget.org/packages/Forbid.Extensions.Microsoft.DependencyInjection/).\n```c#\nusing Forbids;\n\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddForbids(); //default is Singleton, you can pass ServiceLifetime\n}\n```\nand then\n```c#\npublic class TestClassWithDISupport\n{\n    private readonly IForbid _forbid;\n    \n    public TestClassWithDISupport(IForbid forbid)\n    {\n        _forbid = forbid;\n    }\n    \n    public void SomeForbid(int value)\n    {\n        _forbid.Zero(value);\n        // more logic here\n    }\n}\n```\n\n## Extend Forbids\nTo extend forbids, you can do the following:\n```c#\npublic static class TestExtend\n    {\n        public static string Test(this IForbid forbid, string input,Exception exception)\n        {\n            if (input == \"test\")\n                throw exception;\n            return input;\n        }\n    }\n```\nor you can open a pull request and contribute to my project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevazashvili%2Fforbid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frevazashvili%2Fforbid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevazashvili%2Fforbid/lists"}