[Nugsoft-commits] nugsoft/nUGSoft.Entities/Validation MaxBytes.cs,NONE,1.1
Brought to you by:
javery,
jimholmesoh
|
From: Jim H. <jim...@us...> - 2006-01-11 03:03:18
|
Update of /cvsroot/nugsoft/nugsoft/nUGSoft.Entities/Validation In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5611/nUGSoft.Entities/Validation Added Files: MaxBytes.cs Log Message: Initial add. --- NEW FILE: MaxBytes.cs --- using System; //using System.Reflection ; namespace nUGSoft.Entities.Validation { public class MaxBytesAttribute : ValidationBaseAttribute { int _bytes; public MaxBytesAttribute(int Bytes, bool isError, string errorMessage) : base(isError, errorMessage) { _bytes = Bytes; } public int Bytes { get { return _bytes; } } public override bool ValidateValue(object inputValue) { //All validators except the required field validator should //return true if the value is null if (inputValue != null) { byte[] bArr = inputValue as byte[]; if (bArr == null) { throw new ArgumentException("Input wasn't a ByteArray"); } else { if ( bArr.Length <= _bytes) return true; else return false; } } else { return true; } } public override string ErrorMessage { get { if (base.ErrorMessage != String.Empty) return String.Format(base.ErrorMessage, _bytes); else return String.Format("Size cannot exceed {0}", _bytes); } } } } |