Show / Hide Table of Contents

Class CommonResults

Helper class to create instances of RuleResult instances from commonly-used scenarios.

Inheritance
System.Object
CommonResults
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: CSF.Validation.Rules
Assembly: CSF.Validation.Abstractions.dll
Syntax
public static class CommonResults
Remarks

For simplicity of usage consider including using static CSF.Validation.Rules.CommonResults; in your rule implementations.

This class also provides a small performance optimisation for results which do not return a data dictionary (or exception, in the case of error results). When any of these methods are used without data or exceptions then flyweight validation rule result instances will be used. See https://en.wikipedia.org/wiki/Flyweight_pattern for more information.

You may also use an overload of Result(Boolean, IDictionary<String, Object>) or ResultAsync(Boolean, IDictionary<String, Object>) if you wish to use a boolean to indicate pass or failure.

Methods

| Improve this Doc View Source

Error(Exception, Dictionary<String, Object>)

Creates an instance of RuleResult for validation which has encountered an unexpected error.

Declaration
public static RuleResult Error(Exception exception, Dictionary<string, object> data)
Parameters
Type Name Description
System.Exception exception

The exception which caused the error.

System.Collections.Generic.Dictionary<System.String, System.Object> data

A key/value collection of arbitrary validation data.

Returns
Type Description
RuleResult

A RuleResult.

Remarks

Most validation rules do not need to explicitly return error results. If a rule raises an uncaught exception whilst it is being executed then the validation framework will automatically create an error result for that rule, using the unhandled exception raised by the rule.

In normal operation the only times when a rule should explicitly return an error result is either when it also wants to return a dictionary of data, when there are reasons to catch/manipulate the exception before returning the error result or when the "error" does not involve an uncaught exception.

| Improve this Doc View Source

Error(Exception, IDictionary<String, Object>)

Creates an instance of RuleResult for validation which has encountered an unexpected error.

Declaration
public static RuleResult Error(Exception exception = null, IDictionary<string, object> data = null)
Parameters
Type Name Description
System.Exception exception

The exception which caused the error.

System.Collections.Generic.IDictionary<System.String, System.Object> data

An optional key/value collection of arbitrary validation data.

Returns
Type Description
RuleResult

A RuleResult.

Remarks

Most validation rules do not need to explicitly return error results. If a rule raises an uncaught exception whilst it is being executed then the validation framework will automatically create an error result for that rule, using the unhandled exception raised by the rule.

In normal operation the only times when a rule should explicitly return an error result is either when it also wants to return a dictionary of data, when there are reasons to catch/manipulate the exception before returning the error result or when the "error" does not involve an uncaught exception.

| Improve this Doc View Source

ErrorAsync(Exception, Dictionary<String, Object>)

Creates an instance of RuleResult for validation which has encountered an unexpected error, returned within a completed task.

Declaration
public static ValueTask<RuleResult> ErrorAsync(Exception exception, Dictionary<string, object> data)
Parameters
Type Name Description
System.Exception exception

The exception which caused the error.

System.Collections.Generic.Dictionary<System.String, System.Object> data

A key/value collection of arbitrary validation data.

Returns
Type Description
System.Threading.Tasks.ValueTask<RuleResult>

A completed task of RuleResult.

Remarks

Most validation rules do not need to explicitly return error results. If a rule raises an uncaught exception whilst it is being executed then the validation framework will automatically create an error result for that rule, using the unhandled exception raised by the rule.

In normal operation the only times when a rule should explicitly return an error result is either when it also wants to return a dictionary of data, when there are reasons to catch/manipulate the exception before returning the error result or when the "error" does not involve an uncaught exception.

| Improve this Doc View Source

ErrorAsync(Exception, IDictionary<String, Object>)

Creates an instance of RuleResult for validation which has encountered an unexpected error, returned within a completed task.

Declaration
public static ValueTask<RuleResult> ErrorAsync(Exception exception = null, IDictionary<string, object> data = null)
Parameters
Type Name Description
System.Exception exception

The exception which caused the error.

System.Collections.Generic.IDictionary<System.String, System.Object> data

An optional key/value collection of arbitrary validation data.

Returns
Type Description
System.Threading.Tasks.ValueTask<RuleResult>

A RuleResult.

Remarks

Most validation rules do not need to explicitly return error results. If a rule raises an uncaught exception whilst it is being executed then the validation framework will automatically create an error result for that rule, using the unhandled exception raised by the rule.

In normal operation the only times when a rule should explicitly return an error result is either when it also wants to return a dictionary of data, when there are reasons to catch/manipulate the exception before returning the error result or when the "error" does not involve an uncaught exception.

| Improve this Doc View Source

Fail(Dictionary<String, Object>)

Creates an instance of RuleResult for failing validation.

Declaration
public static RuleResult Fail(Dictionary<string, object> data)
Parameters
Type Name Description
System.Collections.Generic.Dictionary<System.String, System.Object> data

A key/value collection of arbitrary validation data.

Returns
Type Description
RuleResult

A RuleResult.

| Improve this Doc View Source

Fail(IDictionary<String, Object>)

Creates an instance of RuleResult for failing validation.

Declaration
public static RuleResult Fail(IDictionary<string, object> data = null)
Parameters
Type Name Description
System.Collections.Generic.IDictionary<System.String, System.Object> data

An optional key/value collection of arbitrary validation data.

Returns
Type Description
RuleResult

A RuleResult.

| Improve this Doc View Source

FailAsync(Dictionary<String, Object>)

Creates an instance of RuleResult for failing validation, returned within a completed task.

Declaration
public static ValueTask<RuleResult> FailAsync(Dictionary<string, object> data)
Parameters
Type Name Description
System.Collections.Generic.Dictionary<System.String, System.Object> data

A key/value collection of arbitrary validation data.

Returns
Type Description
System.Threading.Tasks.ValueTask<RuleResult>

A completed task of RuleResult.

| Improve this Doc View Source

FailAsync(IDictionary<String, Object>)

Creates an instance of RuleResult for failing validation, returned within a completed task.

Declaration
public static ValueTask<RuleResult> FailAsync(IDictionary<string, object> data = null)
Parameters
Type Name Description
System.Collections.Generic.IDictionary<System.String, System.Object> data

An optional key/value collection of arbitrary validation data.

Returns
Type Description
System.Threading.Tasks.ValueTask<RuleResult>

A RuleResult.

| Improve this Doc View Source

Pass(Dictionary<String, Object>)

Creates an instance of RuleResult for passing validation.

Declaration
public static RuleResult Pass(Dictionary<string, object> data)
Parameters
Type Name Description
System.Collections.Generic.Dictionary<System.String, System.Object> data

A key/value collection of arbitrary validation data.

Returns
Type Description
RuleResult

A RuleResult.

| Improve this Doc View Source

Pass(IDictionary<String, Object>)

Creates an instance of RuleResult for passing validation.

Declaration
public static RuleResult Pass(IDictionary<string, object> data = null)
Parameters
Type Name Description
System.Collections.Generic.IDictionary<System.String, System.Object> data

An optional key/value collection of arbitrary validation data.

Returns
Type Description
RuleResult

A RuleResult.

| Improve this Doc View Source

PassAsync(Dictionary<String, Object>)

Creates an instance of RuleResult for passing validation, returned within a completed task.

Declaration
public static ValueTask<RuleResult> PassAsync(Dictionary<string, object> data)
Parameters
Type Name Description
System.Collections.Generic.Dictionary<System.String, System.Object> data

A key/value collection of arbitrary validation data.

Returns
Type Description
System.Threading.Tasks.ValueTask<RuleResult>

A completed task of RuleResult.

| Improve this Doc View Source

PassAsync(IDictionary<String, Object>)

Creates an instance of RuleResult for passing validation, returned within a completed task.

Declaration
public static ValueTask<RuleResult> PassAsync(IDictionary<string, object> data = null)
Parameters
Type Name Description
System.Collections.Generic.IDictionary<System.String, System.Object> data

An optional key/value collection of arbitrary validation data.

Returns
Type Description
System.Threading.Tasks.ValueTask<RuleResult>

A completed task of RuleResult.

| Improve this Doc View Source

Result(Boolean, Dictionary<String, Object>)

Creates an instance of RuleResult for a validation result, either a pass or a fail determined by a boolean parameter.

Declaration
public static RuleResult Result(bool pass, Dictionary<string, object> data)
Parameters
Type Name Description
System.Boolean pass

A value which indicates whether or not the result was a pass. true indicates pass, false indicates failure.

System.Collections.Generic.Dictionary<System.String, System.Object> data

A key/value collection of arbitrary validation data.

Returns
Type Description
RuleResult

A RuleResult.

| Improve this Doc View Source

Result(Boolean, IDictionary<String, Object>)

Creates an instance of RuleResult for a validation result, either a pass or a fail determined by a boolean parameter.

Declaration
public static RuleResult Result(bool pass, IDictionary<string, object> data = null)
Parameters
Type Name Description
System.Boolean pass

A value which indicates whether or not the result was a pass. true indicates pass, false indicates failure.

System.Collections.Generic.IDictionary<System.String, System.Object> data

An optional key/value collection of arbitrary validation data.

Returns
Type Description
RuleResult

A RuleResult.

| Improve this Doc View Source

ResultAsync(Boolean, Dictionary<String, Object>)

Creates an instance of RuleResult for a validation result, either a pass or a fail determined by a boolean parameter, returned within a completed task.

Declaration
public static ValueTask<RuleResult> ResultAsync(bool pass, Dictionary<string, object> data)
Parameters
Type Name Description
System.Boolean pass

A value which indicates whether or not the result was a pass. true indicates pass, false indicates failure.

System.Collections.Generic.Dictionary<System.String, System.Object> data

A key/value collection of arbitrary validation data.

Returns
Type Description
System.Threading.Tasks.ValueTask<RuleResult>

A completed task of RuleResult.

| Improve this Doc View Source

ResultAsync(Boolean, IDictionary<String, Object>)

Creates an instance of RuleResult for a validation result, either a pass or a fail determined by a boolean parameter, returned within a completed task.

Declaration
public static ValueTask<RuleResult> ResultAsync(bool pass, IDictionary<string, object> data = null)
Parameters
Type Name Description
System.Boolean pass

A value which indicates whether or not the result was a pass. true indicates pass, false indicates failure.

System.Collections.Generic.IDictionary<System.String, System.Object> data

An optional key/value collection of arbitrary validation data.

Returns
Type Description
System.Threading.Tasks.ValueTask<RuleResult>

A completed task of RuleResult.

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX