Skip to content

Commit 8725613

Browse files
committed
- Add readme section on WithMessage.
- Add editorconfig.
1 parent 8154560 commit 8725613

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed

.editorconfig

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
[*.cs]
3+
#### Naming styles ####
4+
5+
# Naming rules
6+
7+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
8+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
9+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
10+
11+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
12+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
13+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
14+
15+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
16+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
17+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
18+
19+
# Symbol specifications
20+
21+
dotnet_naming_symbols.interface.applicable_kinds = interface
22+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
23+
dotnet_naming_symbols.interface.required_modifiers =
24+
25+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
26+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
27+
dotnet_naming_symbols.types.required_modifiers =
28+
29+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
30+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
31+
dotnet_naming_symbols.non_field_members.required_modifiers =
32+
33+
# Naming styles
34+
35+
dotnet_naming_style.begins_with_i.required_prefix = I
36+
dotnet_naming_style.begins_with_i.required_suffix =
37+
dotnet_naming_style.begins_with_i.word_separator =
38+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
39+
40+
dotnet_naming_style.pascal_case.required_prefix =
41+
dotnet_naming_style.pascal_case.required_suffix =
42+
dotnet_naming_style.pascal_case.word_separator =
43+
dotnet_naming_style.pascal_case.capitalization = pascal_case
44+
45+
dotnet_naming_style.pascal_case.required_prefix =
46+
dotnet_naming_style.pascal_case.required_suffix =
47+
dotnet_naming_style.pascal_case.word_separator =
48+
dotnet_naming_style.pascal_case.capitalization = pascal_case
49+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
50+
end_of_line = crlf
51+
dotnet_style_coalesce_expression = true:suggestion
52+
dotnet_style_null_propagation = true:suggestion
53+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
54+
dotnet_style_prefer_auto_properties = true:silent
55+
dotnet_style_namespace_match_folder = true:suggestion
56+
57+
csharp_indent_labels = one_less_than_current
58+
csharp_using_directive_placement = outside_namespace:silent
59+
csharp_prefer_simple_using_statement = true:suggestion
60+
csharp_prefer_braces = true:silent
61+
csharp_style_namespace_declarations = file_scoped:error
62+
csharp_style_prefer_method_group_conversion = true:silent
63+
csharp_style_prefer_top_level_statements = true:silent
64+
csharp_style_prefer_primary_constructors = true:suggestion
65+
csharp_prefer_system_threading_lock = true:suggestion
66+
csharp_style_expression_bodied_methods = false:silent
67+
csharp_style_expression_bodied_constructors = false:silent
68+
csharp_style_expression_bodied_operators = false:silent
69+
csharp_style_expression_bodied_properties = true:silent
70+
csharp_style_expression_bodied_indexers = true:silent
71+
csharp_style_expression_bodied_accessors = true:silent
72+
csharp_style_expression_bodied_lambdas = true:silent
73+
csharp_style_expression_bodied_local_functions = false:silent
74+
75+
# Spacing Conventions
76+
77+
[*.{cs,csproj,props,.sln}]
78+
indent_style = space
79+
indent_size = 4
80+
tab_width = 4
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using CodingFlow.FluentValidation;
2+
using CodingFlow.FluentValidation.Validators;
3+
using static CodingFlow.FluentValidation.Validations;
4+
5+
namespace Examples;
6+
7+
internal class WithMessageBasicExample
8+
{
9+
public void Run()
10+
{
11+
var input = 11;
12+
13+
// begin-snippet: WithMessageBasicExample
14+
RuleFor(input)
15+
.Equal(8).WithMessage("The two numbers are not equal.")
16+
.Result();
17+
// end-snippet
18+
}
19+
}

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,22 @@ RuleFor(input)
120120
<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>
121121
<!-- endSnippet -->
122122

123+
# Customizing
124+
125+
## Custom Error Messages
126+
127+
The `WithMessage` method can be used to change the validation error message for a validator.
128+
129+
<!-- snippet: WithMessageBasicExample -->
130+
<a id='snippet-WithMessageBasicExample'></a>
131+
```cs
132+
RuleFor(input)
133+
.Equal(8).WithMessage("The two numbers are not equal.")
134+
.Result();
135+
```
136+
<sup><a href='/Examples/WithMessageBasicExample.cs#L13-L17' title='Snippet source file'>snippet source</a> | <a href='#snippet-WithMessageBasicExample' title='Start of snippet'>anchor</a></sup>
137+
<!-- endSnippet -->
138+
123139
# Integrations
124140

125141
## Vogen

README.source.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ The predicate (aka `Must`) validator allows you to provide your own validation l
5353

5454
snippet: MustBasicExample
5555

56+
# Customizing
57+
58+
## Custom Error Messages
59+
60+
The `WithMessage` method can be used to change the validation error message for a validator.
61+
62+
snippet: WithMessageBasicExample
63+
5664
# Integrations
5765

5866
## Vogen

0 commit comments

Comments
 (0)