trying to localize
This commit is contained in:
parent
a93573dce8
commit
b9a75b71b8
32 changed files with 510 additions and 68 deletions
47
src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs
Normal file
47
src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
|
||||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
public class YaStringLength: YaValidationAttribute
|
||||
{
|
||||
public long MinLen { get; set; } = -1;
|
||||
private long maxLen;
|
||||
public YaStringLength(long maxLen) : base(
|
||||
()=>
|
||||
"BadStringLength")
|
||||
{
|
||||
this.maxLen = maxLen;
|
||||
}
|
||||
|
||||
private long excedent=0;
|
||||
private long manquant=0;
|
||||
|
||||
public override bool IsValid(object value) {
|
||||
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
Console.WriteLine("Validating string length for "+value.ToString());
|
||||
|
||||
string stringValue = value as string;
|
||||
if (stringValue==null) return false;
|
||||
if (MinLen>=0)
|
||||
{
|
||||
if (stringValue.Length<MinLen)
|
||||
{
|
||||
manquant = MinLen-stringValue.Length;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (maxLen>=0)
|
||||
{
|
||||
if (stringValue.Length>maxLen) {
|
||||
excedent = stringValue.Length-maxLen;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue