/// <summary> /// Validates the value. /// </summary> /// <param name="value">The value.</param> /// <param name="nullAllowed">if set to <c>true</c> [null allowed].</param> /// <param name="encoding">The encoding.</param> /// <param name="minLength">The minimum number of bytes when encoded using specified encoding.</param> /// <param name="maxLength">The maximum number of bytes when encoded using specified encoding.</param> public static void ValidateValue(string value, bool nullAllowed, Encoding encoding, int minLength, int maxLength) { if (!nullAllowed || value != null) { int length = ByteUtility.GetByteCount(encoding, value); if (length < minLength || length > maxLength) { throw new ArgumentOutOfRangeException(StringUtility.Format(Resources.ExceptionStringLength, value, minLength, maxLength)); } } }