CuttingEdge.Conditions reference library |
AlternativeExceptionCondition..::.Requires<(Of <(T>)>) Method (T) |
AlternativeExceptionCondition Class Example See Also Send Feedback |
Returns a new ConditionValidator that allows you to
validate the preconditions of the given argument, given it a default ArgumentName of 'value'.
Namespace:
CuttingEdge.Conditions
Assembly:
CuttingEdge.Conditions (in CuttingEdge.Conditions.dll)
Syntax
Visual Basic (Declaration) |
---|
Public MustOverride Function Requires(Of T) ( _ value As T _ ) As ConditionValidator(Of T) |
C# |
---|
public abstract ConditionValidator<T> Requires<T>( T value ) |
Visual C++ |
---|
public: generic<typename T> virtual ConditionValidator<T>^ Requires( T value ) abstract |
JavaScript |
---|
JavaScript does not support generic types or methods. |
Parameters
- value
- Type: T
The value of the argument to validate.
Type Parameters
- T
- The type of the argument to validate.
Return Value
A new ConditionValidator containing the value and "value" as argument name.Examples
The following example shows how to use the Requires extension method.
See the ConditionValidator<(Of <(T>)>) class for more code examples.
Copy Code | |
---|---|
using CuttingEdge.Conditions; public class Person { private int age; public int Age { get { return this.age; } set { // Throws an InvalidOperationException when value is less than 0 Condition.WithExceptionOnFailure<InvalidOperationException>() .Requires(value).IsGreaterOrEqual(0); this.age = value; } } } |