You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,7 @@ ExpressValidator is a library that provides the ability to validate objects usin
18
18
- Supports adding a property or field for validation.
19
19
- Verifies that a property expression is a property and a field expression is a field, and throws `ArgumentException` if it is not.
20
20
- Supports adding a `Func` that provides a value for validation.
21
+
- Provides quick validation (refers to ease of use).
21
22
- Supports asynchronous validation.
22
23
- Targets .NET Standard 2.0+
23
24
@@ -129,6 +130,36 @@ if(!result2.IsValid)
129
130
}
130
131
```
131
132
133
+
## ⏩ Quick Validation
134
+
135
+
Quick validation is convenient for primitive types or types without properties/fields (here, 'quick' refers to usability, not performance). Simply call `QuickValidator.Validate` on the object with a preconfigured rule:
136
+
137
+
```csharp
138
+
varvalue=5;
139
+
// result.IsValid == false
140
+
// result.Errors[0].PropertyName == "value"
141
+
varresult=QuickValidator.Validate(
142
+
value,
143
+
(opt) =>opt.GreaterThan(10),
144
+
nameof(value));
145
+
```
146
+
147
+
For complex types, use FluentValidation's `ChildRules` method:
For `ExpressValidatorBuilder` methods (`AddFunc`, `AddProperty`, and `AddField`), the overridden property name (set via `FluentValidation`'s `OverridePropertyName` method in `With(Async)Validation`) takes precedence over the property name passed as a string or via `Expression` in `AddFunc`/`AddProperty`/`AddField`.
Copy file name to clipboardExpand all lines: src/ExpressValidator/docs/NuGet.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,7 @@ ExpressValidator is a library that provides the ability to validate objects usin
8
8
- Supports adding a property or field for validation.
9
9
- Verifies that a property expression is a property and a field expression is a field, and throws `ArgumentException` if it is not.
10
10
- Supports adding a `Func` that provides a value for validation.
11
+
- Provides quick validation (refers to ease of use).
11
12
- Supports asynchronous validation.
12
13
- Targets .NET Standard 2.0+
13
14
@@ -50,6 +51,7 @@ if(!result.IsValid)
50
51
//As usual with validation result...
51
52
}
52
53
```
54
+
53
55
## Modifying FluentValidation Validator Parameters Using Options
54
56
55
57
To dynamically change the parameters of the `FluentValidation` validators:
@@ -112,3 +114,46 @@ if(!result2.IsValid)
112
114
...
113
115
}
114
116
```
117
+
118
+
## Quick Validation
119
+
120
+
Quick validation is convenient for primitive types or types without properties/fields (here, 'quick' refers to usability, not performance). Simply call `QuickValidator.Validate` on the object with a preconfigured rule:
121
+
122
+
```csharp
123
+
varvalue=5;
124
+
// result.IsValid == false
125
+
// result.Errors[0].PropertyName == "value"
126
+
varresult=QuickValidator.Validate(
127
+
value,
128
+
(opt) =>opt.GreaterThan(10),
129
+
nameof(value));
130
+
```
131
+
132
+
For complex types, use FluentValidation's `ChildRules` method:
For `ExpressValidatorBuilder` methods (`AddFunc`, `AddProperty`, and `AddField`), the overridden property name (set via `FluentValidation`'s `OverridePropertyName` method in `With(Async)Validation`) takes precedence over the property name passed as a string or via `Expression` in `AddFunc`/`AddProperty`/`AddField`.
151
+
For example, for the `ObjToValidate` object from the 'Quick Start' chapter, `result.Errors[0].PropertyName` will equal "percentSum" (the property name overridden in the validation rule):
0 commit comments