Class NotEmpty
A validation rule which passes if the value being validated is either null or is a collection or a string that has at least one item/is not empty.
Inheritance
Implements
Inherited Members
Namespace: CSF.Validation.Rules
Assembly: CSF.Validation.StandardRules.dll
Syntax
public class NotEmpty : IRuleWithMessage<ICollection>, IRule<ICollection>, IGetsFailureMessage<ICollection>, IRuleWithMessage<IEnumerable>, IRule<IEnumerable>, IGetsFailureMessage<IEnumerable>, IRuleWithMessage<Array>, IRule<Array>, IGetsFailureMessage<Array>, IRuleWithMessage<string>, IRule<string>, IGetsFailureMessage<string>
Remarks
For a validated object which implements the non-generic System.
For an object which is simply System.
In some cases enumerating an enumerable in this way will not have undesirable consequences; for some implementations of
System.SELECT * FROM ...
. This could
incur significant performance degradation.
If treating the validated value as non-generic System.
This rule will always return a synchronous result.
Methods
| Improve this Doc View SourceGetResultAsync(Array, RuleContext, CancellationToken)
Performs the validation logic asynchronously and returns a task of Rule
Declaration
public ValueTask<RuleResult> GetResultAsync(Array validated, RuleContext context, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System. |
validated | |
Rule |
context | Contextual information about the validation |
System. |
token | An object which may be used to cancel the process |
Returns
Type | Description |
---|---|
System. |
A task which provides a result object, indicating the result of validation |
Remarks
This method receives the value to be validated as well as an object which represents the
context in which this rule is running.
It should return a task of Rule
In order to create the result object, particularly if your rule logic will run synchronously,
consider using the Commonusing static CSF.Validation.Rules.CommonResults;
in your
rule logic.
The common results class has helper methods such as PassAsync(IDictionary<String, Object>)
and FailAsync(IDictionary<String, Object>)
which include optimisations for flyweight task instances that avoid allocating additional resources
needlessly.
It is acceptable to throw an uncaught exception from this method, as the validation framework will catch it and automatically convert it into an error result. Generally, developers do not need to manually return a result of outcome Errored manually. This would be appropriate only in an unusual scenario that is considered an error, but which does not involve the throwing of an exception. Error results are generally harder for the consumer to deal with than failure results.
The context
parameter may be used, amongst other things, to access 'ancestor'
values.
However, if this rule only needs access to an immediate parent value then consider using
IRule<TValue, TParent> instead.
Exceptions
Type | Condition |
---|---|
System. |
This method may raise any exception type |
GetResultAsync(ICollection, RuleContext, CancellationToken)
Performs the validation logic asynchronously and returns a task of Rule
Declaration
public ValueTask<RuleResult> GetResultAsync(ICollection validated, RuleContext context, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System. |
validated | |
Rule |
context | Contextual information about the validation |
System. |
token | An object which may be used to cancel the process |
Returns
Type | Description |
---|---|
System. |
A task which provides a result object, indicating the result of validation |
Remarks
This method receives the value to be validated as well as an object which represents the
context in which this rule is running.
It should return a task of Rule
In order to create the result object, particularly if your rule logic will run synchronously,
consider using the Commonusing static CSF.Validation.Rules.CommonResults;
in your
rule logic.
The common results class has helper methods such as PassAsync(IDictionary<String, Object>)
and FailAsync(IDictionary<String, Object>)
which include optimisations for flyweight task instances that avoid allocating additional resources
needlessly.
It is acceptable to throw an uncaught exception from this method, as the validation framework will catch it and automatically convert it into an error result. Generally, developers do not need to manually return a result of outcome Errored manually. This would be appropriate only in an unusual scenario that is considered an error, but which does not involve the throwing of an exception. Error results are generally harder for the consumer to deal with than failure results.
The context
parameter may be used, amongst other things, to access 'ancestor'
values.
However, if this rule only needs access to an immediate parent value then consider using
IRule<TValue, TParent> instead.
Exceptions
Type | Condition |
---|---|
System. |
This method may raise any exception type |
GetResultAsync(IEnumerable, RuleContext, CancellationToken)
Performs the validation logic asynchronously and returns a task of Rule
Declaration
public ValueTask<RuleResult> GetResultAsync(IEnumerable validated, RuleContext context, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System. |
validated | |
Rule |
context | Contextual information about the validation |
System. |
token | An object which may be used to cancel the process |
Returns
Type | Description |
---|---|
System. |
A task which provides a result object, indicating the result of validation |
Remarks
This method receives the value to be validated as well as an object which represents the
context in which this rule is running.
It should return a task of Rule
In order to create the result object, particularly if your rule logic will run synchronously,
consider using the Commonusing static CSF.Validation.Rules.CommonResults;
in your
rule logic.
The common results class has helper methods such as PassAsync(IDictionary<String, Object>)
and FailAsync(IDictionary<String, Object>)
which include optimisations for flyweight task instances that avoid allocating additional resources
needlessly.
It is acceptable to throw an uncaught exception from this method, as the validation framework will catch it and automatically convert it into an error result. Generally, developers do not need to manually return a result of outcome Errored manually. This would be appropriate only in an unusual scenario that is considered an error, but which does not involve the throwing of an exception. Error results are generally harder for the consumer to deal with than failure results.
The context
parameter may be used, amongst other things, to access 'ancestor'
values.
However, if this rule only needs access to an immediate parent value then consider using
IRule<TValue, TParent> instead.
Exceptions
Type | Condition |
---|---|
System. |
This method may raise any exception type |
GetResultAsync(String, RuleContext, CancellationToken)
Performs the validation logic asynchronously and returns a task of Rule
Declaration
public ValueTask<RuleResult> GetResultAsync(string validated, RuleContext context, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System. |
validated | |
Rule |
context | Contextual information about the validation |
System. |
token | An object which may be used to cancel the process |
Returns
Type | Description |
---|---|
System. |
A task which provides a result object, indicating the result of validation |
Remarks
This method receives the value to be validated as well as an object which represents the
context in which this rule is running.
It should return a task of Rule
In order to create the result object, particularly if your rule logic will run synchronously,
consider using the Commonusing static CSF.Validation.Rules.CommonResults;
in your
rule logic.
The common results class has helper methods such as PassAsync(IDictionary<String, Object>)
and FailAsync(IDictionary<String, Object>)
which include optimisations for flyweight task instances that avoid allocating additional resources
needlessly.
It is acceptable to throw an uncaught exception from this method, as the validation framework will catch it and automatically convert it into an error result. Generally, developers do not need to manually return a result of outcome Errored manually. This would be appropriate only in an unusual scenario that is considered an error, but which does not involve the throwing of an exception. Error results are generally harder for the consumer to deal with than failure results.
The context
parameter may be used, amongst other things, to access 'ancestor'
values.
However, if this rule only needs access to an immediate parent value then consider using
IRule<TValue, TParent> instead.
Exceptions
Type | Condition |
---|---|
System. |
This method may raise any exception type |
Explicit Interface Implementations
| Improve this Doc View SourceIGetsFailureMessage<Array>.GetFailureMessageAsync(Array, ValidationRuleResult, CancellationToken)
Declaration
ValueTask<string> IGetsFailureMessage<Array>.GetFailureMessageAsync(Array value, ValidationRuleResult result, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
System. |
value | |
Validation |
result | |
System. |
token |
Returns
Type | Description |
---|---|
System. |
IGetsFailureMessage<ICollection>.GetFailureMessageAsync(ICollection, ValidationRuleResult, CancellationToken)
Declaration
ValueTask<string> IGetsFailureMessage<ICollection>.GetFailureMessageAsync(ICollection value, ValidationRuleResult result, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
System. |
value | |
Validation |
result | |
System. |
token |
Returns
Type | Description |
---|---|
System. |
IGetsFailureMessage<IEnumerable>.GetFailureMessageAsync(IEnumerable, ValidationRuleResult, CancellationToken)
Declaration
ValueTask<string> IGetsFailureMessage<IEnumerable>.GetFailureMessageAsync(IEnumerable value, ValidationRuleResult result, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
System. |
value | |
Validation |
result | |
System. |
token |
Returns
Type | Description |
---|---|
System. |
IGetsFailureMessage<String>.GetFailureMessageAsync(String, ValidationRuleResult, CancellationToken)
Declaration
ValueTask<string> IGetsFailureMessage<string>.GetFailureMessageAsync(string value, ValidationRuleResult result, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
System. |
value | |
Validation |
result | |
System. |
token |
Returns
Type | Description |
---|---|
System. |