Skip to content

Commit 21852fc

Browse files
committed
.NET 5 support (fixes #19) (#21)
* Support .NET 5.0
1 parent 9ccdc3f commit 21852fc

File tree

7 files changed

+262
-75
lines changed

7 files changed

+262
-75
lines changed

.gitattributes

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,29 @@ You can download the latest release / pre-release NuGet packages from the offici
1616
3. In startup.cs add `using PeterLeslieMorris.Blazor.Validation` and then add the relevant validation in the `ConfigureServices` method.
1717

1818
- `services.AddFormValidation(config => config.AddDataAnnotationsValidation());`
19-
- `services.AddFormValidation(config => config.AddFluentValidation());`
19+
- `services.AddFormValidation(config => config.AddFluentValidation(typeof(SomeValidator).Assembly));`
2020

2121
It is possible to add as many validation providers as you wish
22-
```
22+
```c#
2323
services.AddFormValidation(config =>
2424
config
2525
.AddDataAnnotationsValidation()
26-
.AddFluentValidation()
26+
.AddFluentValidation(typeof(SomeValidator).Assembly)
2727
);
2828
```
2929

30+
Also you can have the `FluentValidation` extension scan multiple assemblies
31+
32+
```c#
33+
services.AddFormValidation(config =>
34+
config
35+
.AddFluentValidation(
36+
typeof(SomeValidator).Assembly,
37+
typeof(ClassInAnotherDll).Assembly,
38+
andAnotherAssembly,
39+
andYetAnotherAssembly));
40+
```
41+
3042
The standard Blazor components `<ValidationSummary>` and `<ValidationMessage>` will now work with your selected validation options.
3143

3244
### Sample projects
@@ -35,6 +47,9 @@ More sample projects will be added as the framework develops.
3547
- [FluentValidation Sample]- Shows how to use the [FluentValidation.com] library to validate.
3648

3749
## What's new
50+
### New in 1.5.0
51+
- Support .NET 5.0
52+
3853
### New in 1.4.0
3954
- Upgrade to FluentValidation 9
4055

src/.editorconfig

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Data\Mine\Code\blazor-fluxor\src codebase based on best match to current usage at 27/07/2018
2+
# You can modify the rules from these initially generated values to suit your own policies
3+
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
4+
[*.cs]
5+
6+
#Core editorconfig formatting - indentation
7+
8+
#use hard tabs for indentation
9+
indent_style = tab
10+
11+
#Formatting - new line options
12+
13+
#require braces to be on a new line for methods, anonymous_types, accessors, properties, control_blocks, lambdas, and types (also known as "Allman" style)
14+
csharp_new_line_before_open_brace = methods, anonymous_types, accessors, properties, control_blocks, lambdas, types
15+
16+
#Formatting - organize using options
17+
18+
#do not place System.* using directives before other using directives
19+
dotnet_sort_system_directives_first = false
20+
21+
#Formatting - spacing options
22+
23+
#require NO space between a cast and the value
24+
csharp_space_after_cast = false
25+
#require a space before the colon for bases or interfaces in a type declaration
26+
csharp_space_after_colon_in_inheritance_clause = true
27+
#require a space before the colon for bases or interfaces in a type declaration
28+
csharp_space_before_colon_in_inheritance_clause = true
29+
#remove space within empty argument list parentheses
30+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
31+
#remove space between method call name and opening parenthesis
32+
csharp_space_between_method_call_name_and_opening_parenthesis = false
33+
#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call
34+
csharp_space_between_method_call_parameter_list_parentheses = false
35+
#remove space within empty parameter list parentheses for a method declaration
36+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
37+
#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list.
38+
csharp_space_between_method_declaration_parameter_list_parentheses = false
39+
40+
#Formatting - wrapping options
41+
42+
#leave code block on single line
43+
csharp_preserve_single_line_blocks = true
44+
45+
#Style - expression bodied member options
46+
47+
#prefer expression-bodied members for accessors
48+
csharp_style_expression_bodied_accessors = true:suggestion
49+
#prefer block bodies for methods
50+
csharp_style_expression_bodied_methods = false:suggestion
51+
#prefer expression-bodied members for properties
52+
csharp_style_expression_bodied_properties = true:suggestion
53+
54+
#Style - expression level options
55+
56+
#prefer out variables to be declared inline in the argument list of a method call when possible
57+
csharp_style_inlined_variable_declaration = true:suggestion
58+
#prefer the language keyword for member access expressions, instead of the type name, for types that have a keyword to represent them
59+
dotnet_style_predefined_type_for_member_access = true:suggestion
60+
61+
#Style - implicit and explicit types
62+
63+
#prefer explicit type over var to declare variables with built-in system types such as int
64+
csharp_style_var_for_built_in_types = false:suggestion
65+
#prefer var when the type is already mentioned on the right-hand side of a declaration expression
66+
csharp_style_var_when_type_is_apparent = true:suggestion
67+
68+
#Style - language keyword and framework type options
69+
70+
#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them
71+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
72+
73+
#Style - qualification options
74+
75+
#prefer fields not to be prefaced with this. or Me. in Visual Basic
76+
dotnet_style_qualification_for_field = false:suggestion
77+
#prefer methods not to be prefaced with this. or Me. in Visual Basic
78+
dotnet_style_qualification_for_method = false:suggestion
79+
#prefer properties not to be prefaced with this. or Me. in Visual Basic
80+
dotnet_style_qualification_for_property = false:suggestion
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
5-
<SignAssembly>false</SignAssembly>
6-
<AssemblyOriginatorKeyFile>MrPMorris.snk</AssemblyOriginatorKeyFile>
7-
<AssemblyVersion>1.4.0.0</AssemblyVersion>
8-
<FileVersion>1.4.0.0</FileVersion>
9-
<Version>1.4.0</Version>
10-
<Description>FluentValidation for Blazor</Description>
11-
<Copyright>Peter Morris</Copyright>
12-
<PackageLicenseFile>LICENCE</PackageLicenseFile>
13-
<PackageProjectUrl>https://github.com/mrpmorris/blazor-validation</PackageProjectUrl>
14-
<PackageIconUrl>https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png</PackageIconUrl>
15-
<RepositoryUrl>https://github.com/mrpmorris/blazor-validation</RepositoryUrl>
16-
<PackageTags>Blazor FluentValidation</PackageTags>
17-
<DelaySign>false</DelaySign>
18-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
19-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
5+
<SignAssembly>true</SignAssembly>
6+
<AssemblyOriginatorKeyFile>MrPMorris.snk</AssemblyOriginatorKeyFile>
7+
<AssemblyVersion>1.5.0.0</AssemblyVersion>
8+
<FileVersion>1.5.0.0</FileVersion>
9+
<Version>1.5.0</Version>
10+
<Description>FluentValidation for Blazor</Description>
11+
<Copyright>Peter Morris</Copyright>
12+
<PackageLicenseFile>LICENCE</PackageLicenseFile>
13+
<PackageProjectUrl>https://github.com/mrpmorris/blazor-validation</PackageProjectUrl>
14+
<PackageIconUrl>https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png</PackageIconUrl>
15+
<RepositoryUrl>https://github.com/mrpmorris/blazor-validation</RepositoryUrl>
16+
<PackageTags>Blazor FluentValidation</PackageTags>
17+
<DelaySign>false</DelaySign>
18+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
19+
</PropertyGroup>
2020

21-
<ItemGroup>
22-
<PackageReference Include="FluentValidation" Version="9.0.1" />
23-
</ItemGroup>
21+
<ItemGroup>
22+
<PackageReference Include="FluentValidation" Version="9.0.1" />
23+
</ItemGroup>
2424

25-
<ItemGroup>
26-
<None Include="..\..\LICENCE">
27-
<Pack>True</Pack>
28-
<PackagePath></PackagePath>
29-
</None>
30-
</ItemGroup>
25+
<ItemGroup>
26+
<None Include="..\..\LICENCE">
27+
<Pack>True</Pack>
28+
<PackagePath></PackagePath>
29+
</None>
30+
</ItemGroup>
3131

32-
<ItemGroup>
33-
<ProjectReference Include="..\PeterLeslieMorris.Blazor.Validation\PeterLeslieMorris.Blazor.Validation.csproj" />
34-
</ItemGroup>
32+
<ItemGroup>
33+
<ProjectReference Include="..\PeterLeslieMorris.Blazor.Validation\PeterLeslieMorris.Blazor.Validation.csproj" />
34+
</ItemGroup>
3535

3636
</Project>

src/PeterLeslieMorris.Blazor.Validation.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02-FluentValidation", "02-F
1717
EndProject
1818
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Src", "Src", "{451C13F4-69B5-4AB3-B1A8-008A112DE521}"
1919
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentValidationSample", "..\samples\02-FluentValidation\FluentValidationSample\FluentValidationSample.csproj", "{11850E97-B92B-4436-B471-3D43A1802A90}"
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentValidationSample", "..\samples\02-FluentValidation\FluentValidationSample\FluentValidationSample.csproj", "{11850E97-B92B-4436-B471-3D43A1802A90}"
21+
EndProject
22+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A3D40341-FD91-4A62-8EAA-B3548AFD762A}"
23+
ProjectSection(SolutionItems) = preProject
24+
.editorconfig = .editorconfig
25+
..\README.md = ..\README.md
26+
EndProjectSection
2127
EndProject
2228
Global
2329
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/PeterLeslieMorris.Blazor.Validation/Extensions/EditContextExtensions.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,8 @@ private static void NotifyPropertyChanged(
100100
object instance,
101101
string propertyName)
102102
{
103-
if (GetFieldStateMethod == null)
104-
{
105-
GetFieldStateMethod = editContext.GetType().GetMethod(
106-
"GetFieldState",
107-
BindingFlags.NonPublic | BindingFlags.Instance);
108-
}
109-
110103
var fieldIdentifier = new FieldIdentifier(instance, propertyName);
111-
object fieldState = GetFieldStateMethod.Invoke(editContext, new object[] { fieldIdentifier, true });
104+
object fieldState = GetFieldState(editContext, fieldIdentifier);
112105

113106
if (IsModifiedProperty == null)
114107
{
@@ -121,5 +114,31 @@ private static void NotifyPropertyChanged(
121114
editContext.NotifyFieldChanged(fieldIdentifier);
122115
IsModifiedProperty.SetValue(fieldState, originalIsModified);
123116
}
117+
118+
private static Object GetFieldState(EditContext editContext, FieldIdentifier fieldIdentifier)
119+
{
120+
#if (NETSTANDARD2_0 || NETSTANDARD2_1)
121+
Object[] parameters = new object[] { fieldIdentifier, true };
122+
#elif (NET5_0)
123+
Object[] parameters = new object[] { fieldIdentifier };
124+
#endif
125+
EnsureGetFieldStateMethod(editContext);
126+
return GetFieldStateMethod.Invoke(editContext, parameters);
127+
}
128+
129+
private static void EnsureGetFieldStateMethod(EditContext editContext)
130+
{
131+
#if (NETSTANDARD2_0 || NETSTANDARD2_1)
132+
var methodname = "GetFieldState";
133+
#elif (NET5_0)
134+
var methodname = "GetOrAddFieldState";
135+
#endif
136+
137+
if (GetFieldStateMethod == null)
138+
{
139+
GetFieldStateMethod = editContext.GetType().GetMethod(methodname,
140+
BindingFlags.NonPublic | BindingFlags.Instance);
141+
}
142+
}
124143
}
125144
}
Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
5-
<IsPackable>true</IsPackable>
6-
<LangVersion>7.3</LangVersion>
7-
<RazorLangVersion>3.0</RazorLangVersion>
8-
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
9-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
10-
<PackageId>PeterLeslieMorris.Blazor.Validation</PackageId>
11-
<Version>1.4.0</Version>
12-
<Authors>Peter Morris</Authors>
13-
<Company>Peter Morris</Company>
14-
<Product>PeterLeslieMorris.Blazor.Validation</Product>
15-
<Description>Validation for Blazor</Description>
16-
<Copyright>Peter Morris</Copyright>
17-
<PackageLicenseFile>LICENCE</PackageLicenseFile>
18-
<PackageProjectUrl>https://github.com/mrpmorris/blazor-validation</PackageProjectUrl>
19-
<PackageIconUrl>https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png</PackageIconUrl>
20-
<RepositoryUrl>https://github.com/mrpmorris/blazor-validation</RepositoryUrl>
21-
<PackageTags>Blazor Validation</PackageTags>
22-
<AssemblyVersion>1.4.0.0</AssemblyVersion>
23-
<FileVersion>1.4.0.0</FileVersion>
24-
<SignAssembly>false</SignAssembly>
25-
<AssemblyOriginatorKeyFile>MrPMorris.snk</AssemblyOriginatorKeyFile>
26-
<DelaySign>false</DelaySign>
27-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
5+
<IsPackable>true</IsPackable>
6+
<LangVersion>7.3</LangVersion>
7+
<RazorLangVersion>3.0</RazorLangVersion>
8+
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
9+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
10+
<PackageId>PeterLeslieMorris.Blazor.Validation</PackageId>
11+
<Version>1.5.0</Version>
12+
<Authors>Peter Morris</Authors>
13+
<Company>Peter Morris</Company>
14+
<Product>PeterLeslieMorris.Blazor.Validation</Product>
15+
<Description>Validation for Blazor</Description>
16+
<Copyright>Peter Morris</Copyright>
17+
<PackageLicenseFile>LICENCE</PackageLicenseFile>
18+
<PackageProjectUrl>https://github.com/mrpmorris/blazor-validation</PackageProjectUrl>
19+
<PackageIconUrl>https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png</PackageIconUrl>
20+
<RepositoryUrl>https://github.com/mrpmorris/blazor-validation</RepositoryUrl>
21+
<PackageTags>Blazor Validation</PackageTags>
22+
<AssemblyVersion>1.5.0.0</AssemblyVersion>
23+
<FileVersion>1.5.0.0</FileVersion>
24+
<SignAssembly>true</SignAssembly>
25+
<AssemblyOriginatorKeyFile>MrPMorris.snk</AssemblyOriginatorKeyFile>
26+
<DelaySign>false</DelaySign>
27+
</PropertyGroup>
2828

29-
<ItemGroup>
30-
<None Include="..\..\LICENCE">
31-
<Pack>True</Pack>
32-
<PackagePath></PackagePath>
33-
</None>
34-
</ItemGroup>
29+
<ItemGroup>
30+
<None Include="..\..\LICENCE">
31+
<Pack>True</Pack>
32+
<PackagePath></PackagePath>
33+
</None>
34+
</ItemGroup>
3535

36-
<ItemGroup>
37-
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.6" />
38-
</ItemGroup>
36+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
37+
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.6" />
38+
</ItemGroup>
39+
40+
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
41+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0" />
42+
</ItemGroup>
3943

4044
</Project>

0 commit comments

Comments
 (0)