{"id":15011612,"url":"https://github.com/fitomad/fitomad-guard","last_synced_at":"2026-01-05T05:05:27.518Z","repository":{"id":225683452,"uuid":"766582753","full_name":"fitomad/fitomad-guard","owner":"fitomad","description":"A Guard framework for .NET","archived":false,"fork":false,"pushed_at":"2024-03-06T12:42:47.000Z","size":39,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T20:46:37.358Z","etag":null,"topics":["csharp","dotnet","guard","nuget-package"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/Fitomad.Guard/","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/fitomad.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"fitomad","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"polar":null,"custom":null}},"created_at":"2024-03-03T16:59:37.000Z","updated_at":"2024-03-04T23:31:26.000Z","dependencies_parsed_at":"2024-03-03T18:23:38.375Z","dependency_job_id":"9c222e32-63e2-49eb-8177-0d10b217cdd3","html_url":"https://github.com/fitomad/fitomad-guard","commit_stats":{"total_commits":17,"total_committers":2,"mean_commits":8.5,"dds":"0.11764705882352944","last_synced_commit":"091fc02799d6affb5268fd5a6ba1f951f0406110"},"previous_names":["fitomad/fitomad-guard"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitomad%2Ffitomad-guard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitomad%2Ffitomad-guard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitomad%2Ffitomad-guard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitomad%2Ffitomad-guard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fitomad","download_url":"https://codeload.github.com/fitomad/fitomad-guard/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244898406,"owners_count":20528335,"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":["csharp","dotnet","guard","nuget-package"],"created_at":"2024-09-24T19:41:20.529Z","updated_at":"2026-01-05T05:05:27.489Z","avatar_url":"https://github.com/fitomad.png","language":"C#","funding_links":["https://ko-fi.com/fitomad"],"categories":[],"sub_categories":[],"readme":"# Guard clause library for DotNet written in C#\n\nThis package contains a custom class named `Guard` that implements the guard clause for DotNet applications.\n\n## Current guard operations\n\nBelow you will find a list with the guard operations supported grouped by data type.\n\n### Strings\n\n- IsEmpty\n- NotEmpty\n- Length\n- Contains\n- NotContains\n- StarsWith\n- NotStartsWith\n- EndsWith\n- NotEndsWith\n\n### IComparable\n\nNow all types that implements the `IComparable` interface can be used in the following operations\n\n- InRange\n- IsLower\n- IsLowerOrEquals\n- IsGreater\n- IsGreaterOrEquals\n- NotContains\n\n### Equatable\n\nNow all types that implements the `IEquatable` interface can be used in the following operations\n\n- IsEquals\n- NotEquals\n\n### Collections\n\nTypes that implements the `ICollection` interface can be used in the following operations\n\n- Contains\n- NotContains\n- IsEmpty\n- NotEmpty\n\n### Boolean\n\nPerform guard operations for `bool` types\n\n- IsTrue\n- IsFalse\n\n### Regular Expressions\n\nGiven a regular expression, perform guard clause in a `string`\n\n- Match\n- NotMatch \n\n## Example\n\n\n\n```cs\npublic class PaymentEntity\n{\n    public record CreditCard\n    {\n        public string CVV { get; set; }\n        public string CardNumber { get; set; }\n        public string OwnerName { get; set; }\n    }\n\n    public CreditCard Card { get; set; }\n    public List\u003cobject\u003e Cart { get; private set; }\n\n    public PaymentEntity() \n    {\n        Card = new CreditCard();\n        Cart = new List\u003cobject\u003e();\n    }\n\n    public void SetCreditCard(string owner, string number, string cvv)\n    {\n        Card.OwnerName = owner;\n        Card.CardNumber = number;\n        Card.CVV = cvv;\n    }\n\n    public void AddItem(string name)\n    {\n        Cart.Add(name);\n    }\n}\n```\n\nAnd now, let's apply the guard clause to check that parameters are in the expected format.\n\n```cs\nusing Fitomad.Guard;\n\n...\n\npublic void Buy(PaymentEntity entity)\n{\n    Guard.IsNotNull(entity); // Parameter is not null\n    Guard.IsNotNull(entity.Card); // Credit card parameter is not null\n    Guard.NotEmpty(entity.Cart); // There are items in the cart\n\n    Guard.Length(entity.Card.CVV, stringLength: 3); // Card cvv number is 3 characters length\n    Guard.Match(entity.Card.CVV, regularExpression: @\"\\d{3}\"); // Card cvv is only digits\n    Guard.Match(entity.Card.CardNumber, regulaExpression: @\"\\d{4}\\s*\\d{4}\\s*\\d{4}\\s*\\d{4}\"); // Card number format\n    Guard.NotEmpty(entity.Card.OwnerName); // Card owner name is filled\n\n    ...\n}\n```\n\n## Execute custom code if guard clause fails\n\nFitomad.Guard package allow developers to execute custom code in case a guard clause fails\n\n```cs\nGuard.NotEmpty(entity.Cart, perform: () =\u003e \n{\n    Trace.WriteLine(\"The customer part is empty. No products found\");\n});\n```\n\nIn the example above, if guard clause fails the `Trace.WriteLine` code is executed **before** an exception will be throwed. \n\n## Custom Exceptions\n\nYou can also throw your own exceptions in case the guard clause fails.\n\n```cs\nGuard.NotEmpty(entity.Cart, perform: () =\u003e \n{\n    throw new BuyUseCaseException(\"The customer part is empty. No products found\");\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffitomad%2Ffitomad-guard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffitomad%2Ffitomad-guard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffitomad%2Ffitomad-guard/lists"}