NodePipeline/NodePipeline.Abstractions/Attributes/Validation/NodeField/IntValidationAttributes.cs
2026-01-02 20:55:25 +03:00

108 lines
3.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using NodePipeline.Abstractions.Validators;
// ReSharper disable UnusedAutoPropertyAccessor.Global
namespace NodePipeline.Abstractions.Attributes.Validation.NodeField;
//TODO: for analyzer: apply to NodeField<T>, value must be T type where T is integer number
[AttributeUsage(AttributeTargets.Property)]
public sealed class HasValueBetweenAttribute : Attribute
{
/// <summary>
/// Associated with <see cref="NumberRangeValidator{T}" />
/// </summary>
/// <param name="min">String min length non-inclusive</param>
/// <param name="max">String max length non-inclusive</param>
public HasValueBetweenAttribute(decimal min, decimal max)
{
Min = min;
Max = max;
}
/// <summary>
/// Associated with <see cref="NumberRangeValidator{T}" />
/// </summary>
/// <param name="min">String min length non-inclusive</param>
/// <param name="max">String max length non-inclusive</param>
public HasValueBetweenAttribute(int min, decimal max)
{
Min = min;
Max = max;
}
/// <summary>
/// Associated with <see cref="NumberRangeValidator{T}" />
/// </summary>
/// <param name="min">String min length non-inclusive</param>
/// <param name="max">String max length non-inclusive</param>
public HasValueBetweenAttribute(decimal min, int max)
{
Min = min;
Max = max;
}
/// <summary>
/// Associated with <see cref="NumberRangeValidator{T}" />
/// </summary>
/// <param name="min">String min length non-inclusive</param>
/// <param name="max">String max length non-inclusive</param>
public HasValueBetweenAttribute(int min, int max)
{
Min = min;
Max = max;
}
public decimal? Min { get; }
public decimal? Max { get; }
}
//применить к NodeField<T>, value должно быть типа T, где T целые числа
[AttributeUsage(AttributeTargets.Property)]
public sealed class HasMinValueAttribute : Attribute
{
/// <summary>
/// Associated with <see cref="NumberRangeValidator{T}" />
/// </summary>
/// <param name="value">String min length non-inclusive</param>
public HasMinValueAttribute(decimal value)
{
Value = value;
}
/// <summary>
/// Associated with <see cref="NumberRangeValidator{T}" />
/// </summary>
/// <param name="value">String min length non-inclusive</param>
public HasMinValueAttribute(int value)
{
Value = value;
}
public decimal Value { get; }
}
//применить к NodeField<T>, value должно быть типа T, где T целые числа
[AttributeUsage(AttributeTargets.Property)]
public sealed class HasMaxValueAttribute : Attribute
{
/// <summary>
/// Associated with <see cref="NumberRangeValidator{T}" />
/// </summary>
/// <param name="value">String max length non-inclusive</param>
public HasMaxValueAttribute(decimal value)
{
Value = value;
}
/// <summary>
/// Associated with <see cref="NumberRangeValidator{T}" />
/// </summary>
/// <param name="value">String max length non-inclusive</param>
public HasMaxValueAttribute(int value)
{
Value = value;
}
public decimal Value { get; }
}