diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/README.md b/README.md index aff417c..a94243d 100644 --- a/README.md +++ b/README.md @@ -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 `` and `` will now work with your selected validation options. ### Sample projects @@ -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 diff --git a/src/.editorconfig b/src/.editorconfig new file mode 100644 index 0000000..b03b977 --- /dev/null +++ b/src/.editorconfig @@ -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 diff --git a/src/PeterLeslieMorris.Blazor.FluentValidation/PeterLeslieMorris.Blazor.FluentValidation.csproj b/src/PeterLeslieMorris.Blazor.FluentValidation/PeterLeslieMorris.Blazor.FluentValidation.csproj index cbba1be..c1ba307 100644 --- a/src/PeterLeslieMorris.Blazor.FluentValidation/PeterLeslieMorris.Blazor.FluentValidation.csproj +++ b/src/PeterLeslieMorris.Blazor.FluentValidation/PeterLeslieMorris.Blazor.FluentValidation.csproj @@ -1,36 +1,36 @@  - - netstandard2.1 - false - MrPMorris.snk - 1.4.0.0 - 1.4.0.0 - 1.4.0 - FluentValidation for Blazor - Peter Morris - LICENCE - https://github.com/mrpmorris/blazor-validation - https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png - https://github.com/mrpmorris/blazor-validation - Blazor FluentValidation - false - true - + + netstandard2.1;net5.0 + true + MrPMorris.snk + 1.5.0.0 + 1.5.0.0 + 1.5.0 + FluentValidation for Blazor + Peter Morris + LICENCE + https://github.com/mrpmorris/blazor-validation + https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png + https://github.com/mrpmorris/blazor-validation + Blazor FluentValidation + false + true + - - - + + + - - - True - - - + + + True + + + - - - + + + diff --git a/src/PeterLeslieMorris.Blazor.Validation.sln b/src/PeterLeslieMorris.Blazor.Validation.sln index 75c9db1..1d6c3c8 100644 --- a/src/PeterLeslieMorris.Blazor.Validation.sln +++ b/src/PeterLeslieMorris.Blazor.Validation.sln @@ -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 diff --git a/src/PeterLeslieMorris.Blazor.Validation/Extensions/EditContextExtensions.cs b/src/PeterLeslieMorris.Blazor.Validation/Extensions/EditContextExtensions.cs index b7f50e1..1db9c7d 100644 --- a/src/PeterLeslieMorris.Blazor.Validation/Extensions/EditContextExtensions.cs +++ b/src/PeterLeslieMorris.Blazor.Validation/Extensions/EditContextExtensions.cs @@ -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) { @@ -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); + } + } } } diff --git a/src/PeterLeslieMorris.Blazor.Validation/PeterLeslieMorris.Blazor.Validation.csproj b/src/PeterLeslieMorris.Blazor.Validation/PeterLeslieMorris.Blazor.Validation.csproj index 4c2a36e..9ebcd8d 100644 --- a/src/PeterLeslieMorris.Blazor.Validation/PeterLeslieMorris.Blazor.Validation.csproj +++ b/src/PeterLeslieMorris.Blazor.Validation/PeterLeslieMorris.Blazor.Validation.csproj @@ -1,40 +1,44 @@  - - netstandard2.1 - true - 7.3 - 3.0 - true - true - PeterLeslieMorris.Blazor.Validation - 1.4.0 - Peter Morris - Peter Morris - PeterLeslieMorris.Blazor.Validation - Validation for Blazor - Peter Morris - LICENCE - https://github.com/mrpmorris/blazor-validation - https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png - https://github.com/mrpmorris/blazor-validation - Blazor Validation - 1.4.0.0 - 1.4.0.0 - false - MrPMorris.snk - false - + + netstandard2.1;net5.0 + true + 7.3 + 3.0 + true + true + PeterLeslieMorris.Blazor.Validation + 1.5.0 + Peter Morris + Peter Morris + PeterLeslieMorris.Blazor.Validation + Validation for Blazor + Peter Morris + LICENCE + https://github.com/mrpmorris/blazor-validation + https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png + https://github.com/mrpmorris/blazor-validation + Blazor Validation + 1.5.0.0 + 1.5.0.0 + true + MrPMorris.snk + false + - - - True - - - + + + True + + + - - - + + + + + + +