Skip to content

Commit

Permalink
.NET 5 support (fixes #19) (#21)
Browse files Browse the repository at this point in the history
* Support .NET 5.0
  • Loading branch information
mrpmorris committed Nov 11, 2020
1 parent 9ccdc3f commit 21852fc
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 75 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@ You can download the latest release / pre-release NuGet packages from the offici
3. In startup.cs add `using PeterLeslieMorris.Blazor.Validation` and then add the relevant validation in the `ConfigureServices` method.

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

It is possible to add as many validation providers as you wish
```
```c#
services.AddFormValidation(config =>
config
.AddDataAnnotationsValidation()
.AddFluentValidation()
.AddFluentValidation(typeof(SomeValidator).Assembly)
);
```

Also you can have the `FluentValidation` extension scan multiple assemblies

```c#
services.AddFormValidation(config =>
config
.AddFluentValidation(
typeof(SomeValidator).Assembly,
typeof(ClassInAnotherDll).Assembly,
andAnotherAssembly,
andYetAnotherAssembly));
```

The standard Blazor components `<ValidationSummary>` and `<ValidationMessage>` will now work with your selected validation options.

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

## What's new
### New in 1.5.0
- Support .NET 5.0

### New in 1.4.0
- Upgrade to FluentValidation 9

Expand Down
80 changes: 80 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# 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
# You can modify the rules from these initially generated values to suit your own policies
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
[*.cs]

#Core editorconfig formatting - indentation

#use hard tabs for indentation
indent_style = tab

#Formatting - new line options

#require braces to be on a new line for methods, anonymous_types, accessors, properties, control_blocks, lambdas, and types (also known as "Allman" style)
csharp_new_line_before_open_brace = methods, anonymous_types, accessors, properties, control_blocks, lambdas, types

#Formatting - organize using options

#do not place System.* using directives before other using directives
dotnet_sort_system_directives_first = false

#Formatting - spacing options

#require NO space between a cast and the value
csharp_space_after_cast = false
#require a space before the colon for bases or interfaces in a type declaration
csharp_space_after_colon_in_inheritance_clause = true
#require a space before the colon for bases or interfaces in a type declaration
csharp_space_before_colon_in_inheritance_clause = true
#remove space within empty argument list parentheses
csharp_space_between_method_call_empty_parameter_list_parentheses = false
#remove space between method call name and opening parenthesis
csharp_space_between_method_call_name_and_opening_parenthesis = false
#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call
csharp_space_between_method_call_parameter_list_parentheses = false
#remove space within empty parameter list parentheses for a method declaration
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list.
csharp_space_between_method_declaration_parameter_list_parentheses = false

#Formatting - wrapping options

#leave code block on single line
csharp_preserve_single_line_blocks = true

#Style - expression bodied member options

#prefer expression-bodied members for accessors
csharp_style_expression_bodied_accessors = true:suggestion
#prefer block bodies for methods
csharp_style_expression_bodied_methods = false:suggestion
#prefer expression-bodied members for properties
csharp_style_expression_bodied_properties = true:suggestion

#Style - expression level options

#prefer out variables to be declared inline in the argument list of a method call when possible
csharp_style_inlined_variable_declaration = true:suggestion
#prefer the language keyword for member access expressions, instead of the type name, for types that have a keyword to represent them
dotnet_style_predefined_type_for_member_access = true:suggestion

#Style - implicit and explicit types

#prefer explicit type over var to declare variables with built-in system types such as int
csharp_style_var_for_built_in_types = false:suggestion
#prefer var when the type is already mentioned on the right-hand side of a declaration expression
csharp_style_var_when_type_is_apparent = true:suggestion

#Style - language keyword and framework type options

#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
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion

#Style - qualification options

#prefer fields not to be prefaced with this. or Me. in Visual Basic
dotnet_style_qualification_for_field = false:suggestion
#prefer methods not to be prefaced with this. or Me. in Visual Basic
dotnet_style_qualification_for_method = false:suggestion
#prefer properties not to be prefaced with this. or Me. in Visual Basic
dotnet_style_qualification_for_property = false:suggestion
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>MrPMorris.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
<FileVersion>1.4.0.0</FileVersion>
<Version>1.4.0</Version>
<Description>FluentValidation for Blazor</Description>
<Copyright>Peter Morris</Copyright>
<PackageLicenseFile>LICENCE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/mrpmorris/blazor-validation</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png</PackageIconUrl>
<RepositoryUrl>https://github.com/mrpmorris/blazor-validation</RepositoryUrl>
<PackageTags>Blazor FluentValidation</PackageTags>
<DelaySign>false</DelaySign>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>MrPMorris.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>1.5.0.0</AssemblyVersion>
<FileVersion>1.5.0.0</FileVersion>
<Version>1.5.0</Version>
<Description>FluentValidation for Blazor</Description>
<Copyright>Peter Morris</Copyright>
<PackageLicenseFile>LICENCE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/mrpmorris/blazor-validation</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png</PackageIconUrl>
<RepositoryUrl>https://github.com/mrpmorris/blazor-validation</RepositoryUrl>
<PackageTags>Blazor FluentValidation</PackageTags>
<DelaySign>false</DelaySign>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentValidation" Version="9.0.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\LICENCE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENCE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PeterLeslieMorris.Blazor.Validation\PeterLeslieMorris.Blazor.Validation.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PeterLeslieMorris.Blazor.Validation\PeterLeslieMorris.Blazor.Validation.csproj" />
</ItemGroup>

</Project>
8 changes: 7 additions & 1 deletion src/PeterLeslieMorris.Blazor.Validation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02-FluentValidation", "02-F
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Src", "Src", "{451C13F4-69B5-4AB3-B1A8-008A112DE521}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentValidationSample", "..\samples\02-FluentValidation\FluentValidationSample\FluentValidationSample.csproj", "{11850E97-B92B-4436-B471-3D43A1802A90}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentValidationSample", "..\samples\02-FluentValidation\FluentValidationSample\FluentValidationSample.csproj", "{11850E97-B92B-4436-B471-3D43A1802A90}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A3D40341-FD91-4A62-8EAA-B3548AFD762A}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
..\README.md = ..\README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,8 @@ private static void NotifyPropertyChanged(
object instance,
string propertyName)
{
if (GetFieldStateMethod == null)
{
GetFieldStateMethod = editContext.GetType().GetMethod(
"GetFieldState",
BindingFlags.NonPublic | BindingFlags.Instance);
}

var fieldIdentifier = new FieldIdentifier(instance, propertyName);
object fieldState = GetFieldStateMethod.Invoke(editContext, new object[] { fieldIdentifier, true });
object fieldState = GetFieldState(editContext, fieldIdentifier);

if (IsModifiedProperty == null)
{
Expand All @@ -121,5 +114,31 @@ private static void NotifyPropertyChanged(
editContext.NotifyFieldChanged(fieldIdentifier);
IsModifiedProperty.SetValue(fieldState, originalIsModified);
}

private static Object GetFieldState(EditContext editContext, FieldIdentifier fieldIdentifier)
{
#if (NETSTANDARD2_0 || NETSTANDARD2_1)
Object[] parameters = new object[] { fieldIdentifier, true };
#elif (NET5_0)
Object[] parameters = new object[] { fieldIdentifier };
#endif
EnsureGetFieldStateMethod(editContext);
return GetFieldStateMethod.Invoke(editContext, parameters);
}

private static void EnsureGetFieldStateMethod(EditContext editContext)
{
#if (NETSTANDARD2_0 || NETSTANDARD2_1)
var methodname = "GetFieldState";
#elif (NET5_0)
var methodname = "GetOrAddFieldState";
#endif

if (GetFieldStateMethod == null)
{
GetFieldStateMethod = editContext.GetType().GetMethod(methodname,
BindingFlags.NonPublic | BindingFlags.Instance);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<IsPackable>true</IsPackable>
<LangVersion>7.3</LangVersion>
<RazorLangVersion>3.0</RazorLangVersion>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>PeterLeslieMorris.Blazor.Validation</PackageId>
<Version>1.4.0</Version>
<Authors>Peter Morris</Authors>
<Company>Peter Morris</Company>
<Product>PeterLeslieMorris.Blazor.Validation</Product>
<Description>Validation for Blazor</Description>
<Copyright>Peter Morris</Copyright>
<PackageLicenseFile>LICENCE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/mrpmorris/blazor-validation</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png</PackageIconUrl>
<RepositoryUrl>https://github.com/mrpmorris/blazor-validation</RepositoryUrl>
<PackageTags>Blazor Validation</PackageTags>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
<FileVersion>1.4.0.0</FileVersion>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>MrPMorris.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<LangVersion>7.3</LangVersion>
<RazorLangVersion>3.0</RazorLangVersion>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>PeterLeslieMorris.Blazor.Validation</PackageId>
<Version>1.5.0</Version>
<Authors>Peter Morris</Authors>
<Company>Peter Morris</Company>
<Product>PeterLeslieMorris.Blazor.Validation</Product>
<Description>Validation for Blazor</Description>
<Copyright>Peter Morris</Copyright>
<PackageLicenseFile>LICENCE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/mrpmorris/blazor-validation</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png</PackageIconUrl>
<RepositoryUrl>https://github.com/mrpmorris/blazor-validation</RepositoryUrl>
<PackageTags>Blazor Validation</PackageTags>
<AssemblyVersion>1.5.0.0</AssemblyVersion>
<FileVersion>1.5.0.0</FileVersion>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>MrPMorris.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\LICENCE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENCE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.6" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.6" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0" />
</ItemGroup>

</Project>

0 comments on commit 21852fc

Please sign in to comment.