#region Copyright (c) 2009 S. van Deursen
/* The CuttingEdge.Conditions library enables developers to validate pre- and postconditions in a fluent
* manner.
*
* To contact me, please visit my blog at http://www.cuttingedge.it/blogs/steven/
*
* Copyright (c) 2009 S. van Deursen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
* EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#endregion
using System;
namespace CuttingEdge.Conditions
{
// Comparable checks for short
public static partial class ValidatorExtensions
{
/// <summary>
/// Checks whether the given value is between <paramref name="minValue"/> and
/// <paramref name="maxValue"/> (including those values). An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The lowest valid value.</param>
/// <param name="maxValue">The highest valid value.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is not in the specified range, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is not in the specified range, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsInRange(this ConditionValidator<short> validator, short minValue, short maxValue)
{
short value = validator.Value;
if (!(value >= minValue && value <= maxValue))
{
Throw.ValueShouldBeBetween(validator, minValue, maxValue, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is between <paramref name="minValue"/> and
/// <paramref name="maxValue"/> (including those values). An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The lowest valid value.</param>
/// <param name="maxValue">The highest valid value.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is not in the specified range, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is not in the specified range, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsInRange(this ConditionValidator<short> validator, short minValue, short maxValue,
string conditionDescription)
{
short value = validator.Value;
if (!(value >= minValue && value <= maxValue))
{
Throw.ValueShouldBeBetween(validator, minValue, maxValue, conditionDescription);
}
return validator;
}
/// <summary>
/// Checks whether the given value is not between <paramref name="minValue"/> and
/// <paramref name="maxValue"/> (including those values). An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The lowest invalid value.</param>
/// <param name="maxValue">The highest invalid value.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is in the specified range, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is in the specified range, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotInRange(this ConditionValidator<short> validator, short minValue, short maxValue)
{
short value = validator.Value;
if (value >= minValue && value <= maxValue)
{
Throw.ValueShouldNotBeBetween(validator, minValue, maxValue, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is not between <paramref name="minValue"/> and
/// <paramref name="maxValue"/> (including those values). An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The lowest invalid value.</param>
/// <param name="maxValue">The highest invalid value.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is in the specified range, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is in the specified range, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotInRange(this ConditionValidator<short> validator, short minValue, short maxValue,
string conditionDescription)
{
short value = validator.Value;
if (value >= minValue && value <= maxValue)
{
Throw.ValueShouldNotBeBetween(validator, minValue, maxValue, conditionDescription);
}
return validator;
}
/// <summary>
/// Checks whether the given value is greater than the specified <paramref name="minValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The highest invalid value.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller or equal to <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller or equal to <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsGreaterThan(this ConditionValidator<short> validator, short minValue)
{
if (!(validator.Value > minValue))
{
Throw.ValueShouldBeGreaterThan(validator, minValue, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is greater than the specified <paramref name="minValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The highest invalid value.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller or equal to <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller or equal to <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsGreaterThan(this ConditionValidator<short> validator, short minValue,
string conditionDescription)
{
if (!(validator.Value > minValue))
{
Throw.ValueShouldBeGreaterThan(validator, minValue, conditionDescription);
}
return validator;
}
/// <summary>
/// Checks whether the given value is not greater than the specified <paramref name="maxValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="maxValue">The lowest valid value.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater than <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater than <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotGreaterThan(this ConditionValidator<short> validator, short maxValue)
{
if (validator.Value > maxValue)
{
Throw.ValueShouldNotBeGreaterThan(validator, maxValue, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is not greater than the specified <paramref name="maxValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="maxValue">The lowest valid value.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater than <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater than <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotGreaterThan(this ConditionValidator<short> validator, short maxValue,
string conditionDescription)
{
if (validator.Value > maxValue)
{
Throw.ValueShouldNotBeGreaterThan(validator, maxValue, conditionDescription);
}
return validator;
}
/// <summary>
/// Checks whether the given value is greater or equal to the specified <paramref name="minValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The lowest valid value.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller than <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller than <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsGreaterOrEqual(this ConditionValidator<short> validator, short minValue)
{
if (!(validator.Value >= minValue))
{
Throw.ValueShouldBeGreaterThanOrEqualTo(validator, minValue, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is greater or equal to the specified <paramref name="minValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The lowest valid value.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller than <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller than <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsGreaterOrEqual(this ConditionValidator<short> validator, short minValue,
string conditionDescription)
{
if (!(validator.Value >= minValue))
{
Throw.ValueShouldBeGreaterThanOrEqualTo(validator, minValue, conditionDescription);
}
return validator;
}
/// <summary>
/// Checks whether the given value is not greater or equal to the specified <paramref name="maxValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="maxValue">The lowest invalid value.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater or equal to <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater or equal to <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotGreaterOrEqual(this ConditionValidator<short> validator, short maxValue)
{
if (validator.Value >= maxValue)
{
Throw.ValueShouldNotBeGreaterThanOrEqualTo(validator, maxValue, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is not greater or equal to the specified <paramref name="maxValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="maxValue">The lowest invalid value.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater or equal to <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater or equal to <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotGreaterOrEqual(this ConditionValidator<short> validator, short maxValue,
string conditionDescription)
{
if (validator.Value >= maxValue)
{
Throw.ValueShouldNotBeGreaterThanOrEqualTo(validator, maxValue, conditionDescription);
}
return validator;
}
/// <summary>
/// Checks whether the given value is less than the specified <paramref name="maxValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="maxValue">The lowest invalid value.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater or equal to <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater or equal to <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsLessThan(this ConditionValidator<short> validator, short maxValue)
{
if (!(validator.Value < maxValue))
{
Throw.ValueShouldBeSmallerThan(validator, maxValue, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is less than the specified <paramref name="maxValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="maxValue">The lowest invalid value.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater or equal to <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater or equal to <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsLessThan(this ConditionValidator<short> validator, short maxValue,
string conditionDescription)
{
if (!(validator.Value < maxValue))
{
Throw.ValueShouldBeSmallerThan(validator, maxValue, conditionDescription);
}
return validator;
}
/// <summary>
/// Checks whether the given value is not less than the specified <paramref name="minValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The lowest valid value.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller than <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller than <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotLessThan(this ConditionValidator<short> validator, short minValue)
{
if (validator.Value < minValue)
{
Throw.ValueShouldNotBeSmallerThan(validator, minValue, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is not less than the specified <paramref name="minValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The lowest valid value.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller than <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller than <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotLessThan(this ConditionValidator<short> validator, short minValue,
string conditionDescription)
{
if (validator.Value < minValue)
{
Throw.ValueShouldNotBeSmallerThan(validator, minValue, conditionDescription);
}
return validator;
}
/// <summary>
/// Checks whether the given value is smaller or equal to the specified <paramref name="maxValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="maxValue">The highest valid value.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater than <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater than <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsLessOrEqual(this ConditionValidator<short> validator, short maxValue)
{
if (!(validator.Value <= maxValue))
{
Throw.ValueShouldBeSmallerThanOrEqualTo(validator, maxValue, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is smaller or equal to the specified <paramref name="maxValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="maxValue">The highest valid value.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater than <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is greater than <paramref name="maxValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsLessOrEqual(this ConditionValidator<short> validator, short maxValue,
string conditionDescription)
{
if (!(validator.Value <= maxValue))
{
Throw.ValueShouldBeSmallerThanOrEqualTo(validator, maxValue, conditionDescription);
}
return validator;
}
/// <summary>
/// Checks whether the given value is not smaller or equal to the specified <paramref name="minValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The highest invalid value.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller or equal to <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller or equal to <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotLessOrEqual(this ConditionValidator<short> validator, short minValue)
{
if (validator.Value <= minValue)
{
Throw.ValueShouldNotBeSmallerThanOrEqualTo(validator, minValue, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is not smaller or equal to the specified <paramref name="minValue"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="minValue">The highest invalid value.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller or equal to <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is smaller or equal to <paramref name="minValue"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotLessOrEqual(this ConditionValidator<short> validator, short minValue,
string conditionDescription)
{
if (validator.Value <= minValue)
{
Throw.ValueShouldNotBeSmallerThanOrEqualTo(validator, minValue, conditionDescription);
}
return validator;
}
/// <summary>
/// Checks whether the given value is equal to the specified <paramref name="value"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="value">The valid value to compare with.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is not equal to <paramref name="value"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is not equal to <paramref name="value"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsEqualTo(this ConditionValidator<short> validator, short value)
{
if (!(validator.Value == value))
{
Throw.ValueShouldBeEqualTo(validator, value, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is equal to the specified <paramref name="value"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="value">The valid value to compare with.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is not equal to <paramref name="value"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is not equal to <paramref name="value"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsEqualTo(this ConditionValidator<short> validator, short value,
string conditionDescription)
{
if (!(validator.Value == value))
{
Throw.ValueShouldBeEqualTo(validator, value, conditionDescription);
}
return validator;
}
/// <summary>
/// Checks whether the given value is unequal to the specified <paramref name="value"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="value">The invalid value to compare with.</param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is equal to <paramref name="value"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is equal to <paramref name="value"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotEqualTo(this ConditionValidator<short> validator, short value)
{
if (validator.Value == value)
{
Throw.ValueShouldBeUnequalTo(validator, value, null);
}
return validator;
}
/// <summary>
/// Checks whether the given value is unequal to the specified <paramref name="value"/>.
/// An exception is thrown otherwise.
/// </summary>
/// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
/// <param name="value">The invalid value to compare with.</param>
/// <param name="conditionDescription">
/// The description of the condition that should hold. The string may hold the placeholder '{0}' for
/// the <see cref="ConditionValidator{T}.ArgumentName">ArgumentName</see>.
/// </param>
/// <returns>The specified <paramref name="validator"/> instance.</returns>
/// <exception cref="ArgumentException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is equal to <paramref name="value"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
/// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is equal to <paramref name="value"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
public static ConditionValidator<short> IsNotEqualTo(this ConditionValidator<short> validator, short value,
string conditionDescription)
{
if (validator.Value == value)
{
Throw.ValueShouldBeUnequalTo(validator, value, conditionDescription);
}
return validator;
}
}
}