TokenSchedule.FluentValidation
1.1.0
dotnet add package TokenSchedule.FluentValidation --version 1.1.0
NuGet\Install-Package TokenSchedule.FluentValidation -Version 1.1.0
<PackageReference Include="TokenSchedule.FluentValidation" Version="1.1.0" />
paket add TokenSchedule.FluentValidation --version 1.1.0
#r "nuget: TokenSchedule.FluentValidation, 1.1.0"
// Install TokenSchedule.FluentValidation as a Cake Addin #addin nuget:?package=TokenSchedule.FluentValidation&version=1.1.0 // Install TokenSchedule.FluentValidation as a Cake Tool #tool nuget:?package=TokenSchedule.FluentValidation&version=1.1.0
TokenSchedule.FluentValidation
TokenSchedule.FluentValidation is a small library that provides validators for schedule items used in token distribution. It is built on top of FluentValidation to handle validation dependencies separately.
Features
ScheduleItemValidator
: Validates a single schedule item (IValidatedScheduleItem
):- Ensures
Ratio
is positive (> 0
). - Validates that
FinishDate
is either not set or later thanStartDate
.
- Ensures
ScheduleValidator
: Validates an entire schedule (IEnumerable<IValidatedScheduleItem>
):- Schedule cannot be null or empty.
- The sum of all
Ratio
values must be1.0
. - The first item in the schedule must have the earliest
StartDate
(treated as the Token Generation Event). - Each individual item is validated by the
ScheduleItemValidator
.
Installation
You can install this package via the .NET CLI:
dotnet add package TokenSchedule.FluentValidation
Or via the NuGet Package Manager console:
Install-Package TokenSchedule.FluentValidation
Getting Started
Below is a simple example showing how to use TokenSchedule.FluentValidation
:
using System;
using System.Collections.Generic;
using FluentValidation;
using TokenSchedule.FluentValidation;
using TokenSchedule.FluentValidation.Models;
public class MyScheduleItem : IValidatedScheduleItem
{
public decimal Ratio { get; set; }
public DateTime StartDate { get; set; }
public DateTime? FinishDate { get; set; }
}
class Program
{
static void Main()
{
// Create some schedule items
var scheduleItems = new List<IValidatedScheduleItem>
{
new MyScheduleItem
{
Ratio = 0.5m,
StartDate = new DateTime(2024, 1, 1),
FinishDate = new DateTime(2024, 6, 1)
},
new MyScheduleItem
{
Ratio = 0.5m,
StartDate = new DateTime(2024, 6, 2),
FinishDate = new DateTime(2024, 12, 31)
}
};
// Create an instance of the ScheduleValidator
var validator = new ScheduleValidator();
// Validate the schedule
var result = validator.Validate(scheduleItems);
if (result.IsValid)
{
Console.WriteLine("Schedule is valid!");
}
else
{
Console.WriteLine("Schedule is invalid. Errors:");
foreach (var error in result.Errors)
{
Console.WriteLine($"- {error.ErrorMessage}");
}
}
}
}
Explanation
- Define your schedule items by implementing the
IValidatedScheduleItem
interface. - Create a list of schedule items that you want to validate.
- Use the
ScheduleValidator
to validate the entire collection. - Handle the validation results, e.g. by displaying errors or by throwing exceptions.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- FluentValidation (>= 11.11.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TokenSchedule.FluentValidation:
Package | Downloads |
---|---|
TokenSchedule
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.0 | 66 | 12/25/2024 |