添加项目文件。

This commit is contained in:
GG Z
2024-09-22 11:05:41 +08:00
parent fb5d55723a
commit 49ceaae6a8
764 changed files with 78850 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Sai.Toolkit.Mvvm.Attributes;
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public sealed class GreaterThanAttribute : ValidationAttribute
{
public GreaterThanAttribute(string propertyName)
{
PropertyName = propertyName;
}
public string PropertyName { get; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
object instance = validationContext.ObjectInstance,
otherValue = instance.GetType().GetProperty(PropertyName).GetValue(instance);
return ((IComparable)value).CompareTo(otherValue) > 0 ? ValidationResult.Success : new($"当前值小于{value}");
}
}

View File

@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
namespace Sai.Toolkit.Mvvm.Attributes;
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public sealed class IsNumericAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
return double.TryParse(value.ToString(), out var _) ? ValidationResult.Success : new("输入内容不是数值。");
}
}

View File

@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;
namespace Sai.Toolkit.Mvvm.Attributes;
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public sealed class MaximumAttribute : ValidationAttribute
{
public MaximumAttribute(double maxValue = 0)
{
MaxValue = maxValue;
}
public double MaxValue { get; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
return double.TryParse(value.ToString(), out var d) && d <= MaxValue ? ValidationResult.Success : new ValidationResult("输入值超出范围");
}
}

View File

@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;
namespace Sai.Toolkit.Mvvm.Attributes;
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public sealed class MinimumAttribute : ValidationAttribute
{
public MinimumAttribute(double minValue = 0)
{
MinValue = minValue;
}
public double MinValue { get; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
return double.TryParse(value.ToString(), out var d) && d >= MinValue ? ValidationResult.Success : new ValidationResult("ÊäÈëÖµ³¬³ö·¶Î§");
}
}

View File

@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace Sai.Toolkit.Mvvm.Attributes;
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public sealed class NotNullOrEmptyAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var b = value != null || (value is string str && !string.IsNullOrEmpty(str));
return b ? ValidationResult.Success : new("输入内容不是数值。");
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Sai.Toolkit.Mvvm.Attributes
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public class UndefinedCharAttribute : ValidationAttribute
{
public UndefinedCharAttribute(params char[] chars)
{
Chars = chars;
}
public char[] Chars { get; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
//char[] chars = new[] { '\\', ':', '{', '}', '[', ']', '|', ';', '<', '>', '?', '`', '~' };
if (value != null)
{
foreach (var c in Chars)
{
if (value.ToString().IndexOf(c) > -1)
{
return new ValidationResult($"输入字符不合法,名称不能包含字符:'\\ : [ ] | {{}}; < > ? ` ~");
}
}
}
return ValidationResult.Success;
}
}
}