Class IsTrueValidator
- Namespace
- Acuit.Pinpoint.Workflows.Testing.Validation
- Assembly
- Acuit.Pinpoint.Workflows.Testing.dll
A validator that validates that a data value is considered true.
public class IsTrueValidator : IDataValueValidator
- Inheritance
-
IsTrueValidator
- Implements
- Inherited Members
Remarks
This will work with any data value. It determines whether a data value is considered true or false according to this logic:
- If the data value is null, it is considered false. This includes nullable bool types with a null value.
- If the data value can be converted to a bool, the converted value is used.
The following data values can be converted to a bool:
- bool values. This includes nullable bool types with a non-null value.
- String values of "True" or "False" (case-insensitive).
- Numeric values (e.g., int, float, double, byte, decimal, etc.) will be considered true if non-zero, or false if zero.
- Any other type with a type converter or that implements IConvertible that supports converting to a bool.
- If the data value can be converted to an int, then it is considered true if non-zero, or false if zero. This will handle strings that can be parsed as an int (using the invariant culture) or any other type with a type converter or that implements IConvertible that supports converting to an int.
- If the data value can be converted to a double, then it is considered true if non-zero, or false if zero. This will handle strings that can be parsed as a double (using the invariant culture) or any other type with a type converter or that implements IConvertible that supports converting to an double.
- Otherwise, the data value is converted to a string (using the invariant culture), and then it is considered true if it is not empty, or false if it is empty (i.e., zero length).
Methods
InitializeAsync(ActivityContext, IDataValueDescriptor, CancellationToken)
Initializes the validator.
public Task<IInitializedDataValueValidator> InitializeAsync(ActivityContext context, IDataValueDescriptor dataValueDescriptor, CancellationToken cancellationToken)
Parameters
context
ActivityContextThe activity context.
dataValueDescriptor
IDataValueDescriptorThe data value descriptor.
cancellationToken
CancellationTokenA CancellationToken that can request cancellation.
Returns
- Task<IInitializedDataValueValidator>
A task that represents the asynchronous operation. The value of its Result property contains an IInitializedDataValueValidator representing the initialized validator.
Exceptions
- ArgumentNullException
context
is null.- ArgumentNullException
dataValueDescriptor
is null.- Exception
The validator could not be initialized. The exception type will depend on the implementation.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.