Re-fabrication
This commit is contained in:
parent
f155a47073
commit
cb6309abdb
499 changed files with 7574 additions and 12530 deletions
58
Yavsc.Server/Attributes/Validation/YaStringLength.cs
Normal file
58
Yavsc.Server/Attributes/Validation/YaStringLength.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
public class YaStringLength: YaValidationAttribute
|
||||
{
|
||||
public long MinLen { get; set; } = -1;
|
||||
private long maxLen;
|
||||
public YaStringLength(long maxLen) : base(
|
||||
()=>string.Format(
|
||||
ResourcesHelpers.DefaultResourceManager.GetString("BadStringLength"),
|
||||
maxLen))
|
||||
{
|
||||
this.maxLen = maxLen;
|
||||
}
|
||||
|
||||
private long excedent;
|
||||
private long manquant;
|
||||
|
||||
public override bool IsValid(object value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
if (MinLen<0) {
|
||||
// DetailledMaxStringLength
|
||||
return string.Format(
|
||||
ResourcesHelpers.DefaultResourceManager.GetString("DetailledMaxStringLength"),
|
||||
maxLen,
|
||||
excedent);
|
||||
} else
|
||||
return string.Format(
|
||||
ResourcesHelpers.DefaultResourceManager.GetString("DetailledMinMaxStringLength"),
|
||||
MinLen,
|
||||
maxLen,
|
||||
manquant,
|
||||
excedent);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue