{"id":17008453,"url":"https://github.com/linkdotnet/validationextensions","last_synced_at":"2025-04-12T07:34:02.939Z","repository":{"id":43376325,"uuid":"459726442","full_name":"linkdotnet/ValidationExtensions","owner":"linkdotnet","description":"Small library to extend validation attributes on blazor forms","archived":false,"fork":false,"pushed_at":"2024-11-14T07:37:20.000Z","size":883,"stargazers_count":14,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-08T11:05:00.631Z","etag":null,"topics":["attributes","blazor","csharp","forms","validation"],"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/linkdotnet.png","metadata":{"files":{"readme":"Readme.md","changelog":"CHANGELOG.md","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-15T19:46:53.000Z","updated_at":"2025-01-14T17:35:55.000Z","dependencies_parsed_at":"2023-02-10T06:15:17.879Z","dependency_job_id":null,"html_url":"https://github.com/linkdotnet/ValidationExtensions","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FValidationExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FValidationExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FValidationExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FValidationExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkdotnet","download_url":"https://codeload.github.com/linkdotnet/ValidationExtensions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248534624,"owners_count":21120385,"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":["attributes","blazor","csharp","forms","validation"],"created_at":"2024-10-14T05:28:19.902Z","updated_at":"2025-04-12T07:34:02.907Z","avatar_url":"https://github.com/linkdotnet.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ValidationExtensions\n\n[![.NET](https://github.com/linkdotnet/ValidationExtensions/actions/workflows/dotnet.yml/badge.svg)](https://github.com/linkdotnet/ValidationExtensions/actions/workflows/dotnet.yml)\n[![nuget](https://img.shields.io/nuget/v/LinkDotNet.ValidationExtensions)](https://www.nuget.org/packages/LinkDotNet.ValidationExtensions)\n\nThe motivation behind this small project is simple. Just imagine you have the following model in Blazor:\n```csharp\npublic class MyModel\n{\n    [Required]\n    public string Title { get; set; }\n\n    [Required]\n    public string Content { get; set; }\n\n    [Required]\n    public bool IsPublished { get; set; }\n}\n```\n\nNow as a consumer you have to provide all of those 3 values. That is all good and nice, but what if we want to say:\n\"Okay as long as it doesn't get published, we don't have to provide the content?\". Well that does not work with the default implementation.\n\nHere is where this small library comes into play:\n```csharp\npublic class MyModel\n{\n    [Required]\n    public string Title { get; set; }\n\n    [RequiredIf(nameof(IsPublished), true)]\n    public string Content { get; set; }\n\n    [Required]\n    public bool IsPublished { get; set; }\n}\n```\n\nNow `Title` will always be required. But as long as `IsPublished` is false `Content` can be null or empty.\n\n## Get Started\nTo install either go the [nuget](https://www.nuget.org/packages/LinkDotNet.ValidationExtensions) or execute the following command:\n```\ndotnet add LinkDotNet.ValidationExtensions\n```\n\n## Example\n```csharp\nusing LinkDotNet.ValidationExtensions;\n\npublic class BlogArticle\n{\n    [Required]\n    public string Title { get; set; }\n\n    [RequiredIf(nameof(IsPublished), true)]\n    public string ArticleContent { get; set; }\n\n    [RequiredIfNot(nameof(ArticleContent), null)]\n    public string ReplacementContent { get; set; }\n    \n    [Required]\n    public bool? NoticeByEmail { get; set; }\n\n    [RequiredDynamic(nameof(ValidateRequired_NoticeByEmail), \"Notice by email is activated\")]\n    public string? EmailAddress { get; set; }\n    \n    [DynamicRange(typeof(decimal), minimum: 9.99, maximumPropertyName: nameof(MaximumPrice))]\n    public decimal? MinimumPrice { get; set; }\n\n    [DynamicRange(typeof(decimal), minimumPropertyName: nameof(MinimumPrice), maximum: 199.99)]\n    public decimal? MaximumPrice { get; set; }\n\n    [DynamicRange\u003cdouble\u003e(minimum: 0.1d, maximumPropertyName: nameof(MaximumWeight))]\n    public double? MinimumWeight { get; set; }\n\n    [DynamicRange\u003cdouble\u003e(minimumPropertyName: nameof(MinimumWeight), maximum: 500d)]\n    public double? MaximumWeight { get; set; }\n\n    private static bool ValidateRequired_NoticeByEmail(BlogArticle value)\n    {\n        if (!value.NoticeByEmail.HasValue)\n        {\n            return false;\n        }\n\n        if (!value.NoticeByEmail.Value)\n        {\n            return false;\n        }\n\n        if (string.IsNullOrWhiteSpace(value.EmailAddress))\n        {\n            return true;\n        }\n        else\n        {\n            return false;\n        }\n    }\n}\n```\n\n## Currently implemented additional attributes:\n * `RequiredIf`\n * `MinLengthIf` / `MaxLengthIf`\n * `RangeIf`\n * `MinIf` / `MaxIf`\n * `Min` / `Max`\n * `Dynamic`\n * `DynamicRange` \n * `DynamicRange\u003cT\u003e` [C# 11 Generic Attributes](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-11.0/generic-attributes)\n * `FutureDateValidation` / `PastDateValidation`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdotnet%2Fvalidationextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkdotnet%2Fvalidationextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdotnet%2Fvalidationextensions/lists"}