Skip to content

Commit 91aeac9

Browse files
committed
Add documentation for each validator to readme.
1 parent a2bd25d commit 91aeac9

File tree

7 files changed

+200
-2
lines changed

7 files changed

+200
-2
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using CodingFlow.FluentValidation.Validators;
2+
using static CodingFlow.FluentValidation.Validations;
3+
4+
namespace Examples;
5+
6+
internal class BetweenExclusiveBasicExample
7+
{
8+
public void Run()
9+
{
10+
var input = 11;
11+
12+
// begin-snippet: BetweenExclusiveBasicExample
13+
RuleFor(input)
14+
.BetweenExclusive(6, 14)
15+
.Result();
16+
// end-snippet
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using CodingFlow.FluentValidation.Validators;
2+
using static CodingFlow.FluentValidation.Validations;
3+
4+
namespace Examples;
5+
6+
internal class BetweenInclusiveBasicExample
7+
{
8+
public void Run()
9+
{
10+
var input = 11;
11+
12+
// begin-snippet: BetweenInclusiveBasicExample
13+
RuleFor(input)
14+
.BetweenInclusive(6, 14)
15+
.Result();
16+
// end-snippet
17+
}
18+
}

Examples/EqualBasicExample.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using CodingFlow.FluentValidation.Validators;
2+
using static CodingFlow.FluentValidation.Validations;
3+
4+
namespace Examples;
5+
6+
internal class EqualBasicExample
7+
{
8+
public void Run()
9+
{
10+
var input = 11;
11+
12+
// begin-snippet: EqualBasicExample
13+
RuleFor(input)
14+
.Equal(8)
15+
.Result();
16+
// end-snippet
17+
}
18+
}

Examples/MustBasicExample.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using CodingFlow.FluentValidation.Validators;
2+
using static CodingFlow.FluentValidation.Validations;
3+
4+
namespace Examples;
5+
6+
internal class MustBasicExample
7+
{
8+
public void Run()
9+
{
10+
var input = 11;
11+
12+
// begin-snippet: MustBasicExample
13+
RuleFor(input)
14+
.Must(input => input == 7)
15+
.Result();
16+
// end-snippet
17+
}
18+
}

Examples/NotEmptyBasicExample.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using CodingFlow.FluentValidation.Validators;
2+
using static CodingFlow.FluentValidation.Validations;
3+
4+
namespace Examples;
5+
6+
internal class NotEmptyBasicExample
7+
{
8+
public void Run()
9+
{
10+
var input = 11;
11+
12+
// begin-snippet: NotEmptyBasicExample
13+
RuleFor(input)
14+
.NotEmpty()
15+
.Result();
16+
// end-snippet
17+
}
18+
}

README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,85 @@ var errors = result.Errors;
4646
<sup><a href='/Examples/BasicExample.cs#L12-L22' title='Snippet source file'>snippet source</a> | <a href='#snippet-BasicExample' title='Start of snippet'>anchor</a></sup>
4747
<!-- endSnippet -->
4848

49+
# Validators
50+
51+
There are several built-in validators available out-of-the-box. You can also provide your own validation logic via the [predicate validator](#predicate-validator) (aka `Must`).
52+
53+
## NotEmpty Validator
54+
55+
Ensures the value is not `null` for reference types or a default value for value types. For strings, ensures it is not `null`, an empty string, or only whitespace.
56+
57+
<!-- snippet: NotEmptyBasicExample -->
58+
<a id='snippet-NotEmptyBasicExample'></a>
59+
```cs
60+
RuleFor(input)
61+
.NotEmpty()
62+
.Result();
63+
```
64+
<sup><a href='/Examples/NotEmptyBasicExample.cs#L12-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-NotEmptyBasicExample' title='Start of snippet'>anchor</a></sup>
65+
<!-- endSnippet -->
66+
67+
## BetweenInclusive Validator
68+
69+
Ensures a number of any type (`int`, `float`, `double`, etc.) is greater than a minimum and less than a maximum.
70+
71+
<!-- snippet: BetweenInclusiveBasicExample -->
72+
<a id='snippet-BetweenInclusiveBasicExample'></a>
73+
```cs
74+
RuleFor(input)
75+
.BetweenInclusive(6, 14)
76+
.Result();
77+
```
78+
<sup><a href='/Examples/BetweenInclusiveBasicExample.cs#L12-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-BetweenInclusiveBasicExample' title='Start of snippet'>anchor</a></sup>
79+
<!-- endSnippet -->
80+
81+
## BetweenExclusive Validator
82+
83+
Ensures a number of any type (`int`, `float`, `double`, etc.) is greater than or equal to a minimum and less than or equal to a maximum.
84+
85+
<!-- snippet: BetweenExclusiveBasicExample -->
86+
<a id='snippet-BetweenExclusiveBasicExample'></a>
87+
```cs
88+
RuleFor(input)
89+
.BetweenExclusive(6, 14)
90+
.Result();
91+
```
92+
<sup><a href='/Examples/BetweenExclusiveBasicExample.cs#L12-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-BetweenExclusiveBasicExample' title='Start of snippet'>anchor</a></sup>
93+
<!-- endSnippet -->
94+
95+
## Equal Validator
96+
97+
Ensures the input is considered equal to the provided value. For reference types it checks if the two references are to the same instance (reference equality). For value types, it checks it the types and values are the same (value equality).
98+
99+
<!-- snippet: EqualBasicExample -->
100+
<a id='snippet-EqualBasicExample'></a>
101+
```cs
102+
RuleFor(input)
103+
.Equal(8)
104+
.Result();
105+
```
106+
<sup><a href='/Examples/EqualBasicExample.cs#L12-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-EqualBasicExample' title='Start of snippet'>anchor</a></sup>
107+
<!-- endSnippet -->
108+
109+
## Predicate Validator
110+
111+
The predicate (aka `Must`) validator allows you to provide your own validation logic by providing a delegate.
112+
113+
<!-- snippet: MustBasicExample -->
114+
<a id='snippet-MustBasicExample'></a>
115+
```cs
116+
RuleFor(input)
117+
.Must(input => input == 7)
118+
.Result();
119+
```
120+
<sup><a href='/Examples/MustBasicExample.cs#L12-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-MustBasicExample' title='Start of snippet'>anchor</a></sup>
121+
<!-- endSnippet -->
122+
49123
# Integrations
50124

51125
## Vogen
52126

53-
Extensions to integrate with Vogen validation methods.
127+
Extensions to integrate with [Vogen](https://github.com/SteveDunn/Vogen) validation methods.
54128

55129
To get started, install the Vogen extensions nuget package, `CodingFlow.FluentValidation.VogenExtensions`.
56130

README.source.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,45 @@ Then you can add validation like this:
1919

2020
snippet: BasicExample
2121

22+
# Validators
23+
24+
There are several built-in validators available out-of-the-box. You can also provide your own validation logic via the [predicate validator](#predicate-validator) (aka `Must`).
25+
26+
## NotEmpty Validator
27+
28+
Ensures the value is not `null` for reference types or a default value for value types. For strings, ensures it is not `null`, an empty string, or only whitespace.
29+
30+
snippet: NotEmptyBasicExample
31+
32+
## BetweenInclusive Validator
33+
34+
Ensures a number of any type (`int`, `float`, `double`, etc.) is greater than a minimum and less than a maximum.
35+
36+
snippet: BetweenInclusiveBasicExample
37+
38+
## BetweenExclusive Validator
39+
40+
Ensures a number of any type (`int`, `float`, `double`, etc.) is greater than or equal to a minimum and less than or equal to a maximum.
41+
42+
snippet: BetweenExclusiveBasicExample
43+
44+
## Equal Validator
45+
46+
Ensures the input is considered equal to the provided value. For reference types it checks if the two references are to the same instance (reference equality). For value types, it checks it the types and values are the same (value equality).
47+
48+
snippet: EqualBasicExample
49+
50+
## Predicate Validator
51+
52+
The predicate (aka `Must`) validator allows you to provide your own validation logic by providing a delegate.
53+
54+
snippet: MustBasicExample
55+
2256
# Integrations
2357

2458
## Vogen
2559

26-
Extensions to integrate with Vogen validation methods.
60+
Extensions to integrate with [Vogen](https://github.com/SteveDunn/Vogen) validation methods.
2761

2862
To get started, install the Vogen extensions nuget package, `CodingFlow.FluentValidation.VogenExtensions`.
2963

0 commit comments

Comments
 (0)