localizing bug record creations
This commit is contained in:
parent
6bde0a51cf
commit
2ed3b7e576
7 changed files with 63 additions and 99 deletions
|
|
@ -4,17 +4,16 @@ namespace Yavsc.Attributes.Validation
|
|||
{
|
||||
public class YaStringLength: YaValidationAttribute
|
||||
{
|
||||
public long MinLen { get; set; } = -1;
|
||||
public long MinimumLength { get; set; } = -1;
|
||||
private long maxLen;
|
||||
public YaStringLength(long maxLen) : base(
|
||||
()=>
|
||||
"BadStringLength")
|
||||
public YaStringLength(long maxLen) : base( ()=> "BadStringLength")
|
||||
{
|
||||
this.maxLen = maxLen;
|
||||
}
|
||||
|
||||
private long excedent=0;
|
||||
private long manquant=0;
|
||||
// hugly ...
|
||||
static long excedent=0;
|
||||
static long manquant=0;
|
||||
|
||||
public override bool IsValid(object value) {
|
||||
|
||||
|
|
@ -24,23 +23,24 @@ namespace Yavsc.Attributes.Validation
|
|||
|
||||
string stringValue = value as string;
|
||||
if (stringValue==null) return false;
|
||||
if (MinLen>=0)
|
||||
if (MinimumLength>=0)
|
||||
{
|
||||
if (stringValue.Length<MinLen)
|
||||
{
|
||||
manquant = MinLen-stringValue.Length;
|
||||
}
|
||||
if (stringValue.Length< MinimumLength)
|
||||
return false;
|
||||
}
|
||||
if (maxLen>=0)
|
||||
{
|
||||
if (stringValue.Length>maxLen) {
|
||||
excedent = stringValue.Length-maxLen;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
var temp = base.FormatErrorMessage(name);
|
||||
return string.Format(temp, MinimumLength, maxLen);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -15,18 +15,32 @@ namespace Yavsc.Attributes.Validation
|
|||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get given string from resources
|
||||
/// specified by ErrorMessageResourceType
|
||||
/// </summary>
|
||||
/// <param name="stringName"></param>
|
||||
/// <returns></returns>
|
||||
public virtual string GetResourceString(string stringName)
|
||||
{
|
||||
var prop = this.ErrorMessageResourceType.GetProperty(stringName);
|
||||
if (prop==null)
|
||||
{
|
||||
return " !e! noprop "+stringName+" in "+ErrorMessageResourceType.Name;
|
||||
}
|
||||
else {
|
||||
return (string) prop.GetValue(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
if (ErrorMessageResourceType == null) // failed :/
|
||||
return name;
|
||||
return base.FormatErrorMessage(name);
|
||||
if (ErrorMessageResourceName == null) // re failed :/
|
||||
return name;
|
||||
return base.FormatErrorMessage(name);
|
||||
|
||||
var prop = this.ErrorMessageResourceType.GetProperty(ErrorMessageResourceName);
|
||||
if (prop==null) // re re failed :/
|
||||
return "noprop "+ErrorMessageResourceName+" in "+ErrorMessageResourceType.Name;
|
||||
return (string) prop.GetValue(null, null);
|
||||
|
||||
return GetResourceString(ErrorMessageResourceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue