LinkDotNet.ValidationExtensions 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package LinkDotNet.ValidationExtensions --version 2.0.0                
NuGet\Install-Package LinkDotNet.ValidationExtensions -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LinkDotNet.ValidationExtensions" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LinkDotNet.ValidationExtensions --version 2.0.0                
#r "nuget: LinkDotNet.ValidationExtensions, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LinkDotNet.ValidationExtensions as a Cake Addin
#addin nuget:?package=LinkDotNet.ValidationExtensions&version=2.0.0

// Install LinkDotNet.ValidationExtensions as a Cake Tool
#tool nuget:?package=LinkDotNet.ValidationExtensions&version=2.0.0                

ValidationExtensions

.NET nuget

The motivation behind this small project is simple. Just imagine you have the following model in Blazor:

public class MyModel
{
    [Required]
    public string Title { get; set; }

    [Required]
    public string Content { get; set; }

    [Required]
    public bool IsPublished { get; set; }
}

Now 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: "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.

Here is where this small library comes into play:

public class MyModel
{
    [Required]
    public string Title { get; set; }

    [RequiredIf(nameof(IsPublished), true)]
    public string Content { get; set; }

    [Required]
    public bool IsPublished { get; set; }
}

Now Title will always be required. But as long as IsPublished is false Content can be null or empty.

Get Started

To install either go the nuget or execute the following command:

dotnet add LinkDotNet.ValidationExtensions

Example

using LinkDotNet.ValidationExtensions;

public class BlogArticle
{
    [Required]
    public string Title { get; set; }

    [RequiredIf(nameof(IsPublished), true)]
    public string ArticleContent { get; set; }

    [RequiredIfNot(nameof(ArticleContent), null)]
    public string ReplacementContent { get; set; }
}

Currently implemented additional attributes:

  • RequiredIf
  • MinLengthIf / MaxLengthIf
  • RangeIf
  • MinIf / MaxIf
  • Min / Max
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.6.0 5,154 7/7/2023
2.5.1 721 4/16/2023
2.5.0 305 3/27/2023
2.4.0 308 1/16/2023
2.3.2 293 1/9/2023
2.2.0 305 1/3/2023
2.1.0 474 3/4/2022
2.0.0 426 2/17/2022
1.1.0 423 2/16/2022
1.0.0 443 2/15/2022