diff --git a/Enciphered.Blazor.UIComponents.Demo/Enciphered.Blazor.UIComponents.Demo.csproj b/Enciphered.Blazor.UIComponents.Demo/Enciphered.Blazor.UIComponents.Demo.csproj index 4336ecc..294f058 100644 --- a/Enciphered.Blazor.UIComponents.Demo/Enciphered.Blazor.UIComponents.Demo.csproj +++ b/Enciphered.Blazor.UIComponents.Demo/Enciphered.Blazor.UIComponents.Demo.csproj @@ -1,15 +1,15 @@ + + net10.0 + enable + enable + true + - - net9.0 - enable - enable - - diff --git a/Enciphered.Blazor.UIComponents/Enciphered.Blazor.UIComponents.csproj b/Enciphered.Blazor.UIComponents/Enciphered.Blazor.UIComponents.csproj index a237c0e..8cb675a 100644 --- a/Enciphered.Blazor.UIComponents/Enciphered.Blazor.UIComponents.csproj +++ b/Enciphered.Blazor.UIComponents/Enciphered.Blazor.UIComponents.csproj @@ -1,9 +1,10 @@ - net9.0 + net10.0 enable enable + true @@ -12,11 +13,7 @@ - - - - diff --git a/Enciphered.Blazor.UIComponents/Forms/Validation/FormModelBinder.cs b/Enciphered.Blazor.UIComponents/Forms/Validation/FormModelBinder.cs index 6b5b107..7b870a9 100644 --- a/Enciphered.Blazor.UIComponents/Forms/Validation/FormModelBinder.cs +++ b/Enciphered.Blazor.UIComponents/Forms/Validation/FormModelBinder.cs @@ -1,19 +1,22 @@ + using System.Globalization; using System.Reflection; +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Http; namespace Enciphered.Blazor.UIComponents.Validation; public static class FormModelBinder { - public static TModel Bind(IFormCollection form) where TModel : new() + public static TModel Bind<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] TModel>(IFormCollection form) where TModel : new() { var model = new TModel(); - var props = typeof(TModel).GetProperties(BindingFlags.Public | BindingFlags.Instance) - .Where(p => p.CanWrite); + PropertyInfo[] props = typeof(TModel).GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var prop in props) { + if (!prop.CanWrite) continue; + var key = form.Keys.FirstOrDefault(k => string.Equals(k, prop.Name, StringComparison.OrdinalIgnoreCase)); diff --git a/Enciphered.Blazor.UIComponents/Forms/Validation/HtmxFormValidationExtensions.cs b/Enciphered.Blazor.UIComponents/Forms/Validation/HtmxFormValidationExtensions.cs index d0ea91f..2c163ee 100644 --- a/Enciphered.Blazor.UIComponents/Forms/Validation/HtmxFormValidationExtensions.cs +++ b/Enciphered.Blazor.UIComponents/Forms/Validation/HtmxFormValidationExtensions.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; @@ -17,7 +18,7 @@ public static class HtmxFormValidationExtensions return MapEndpoints(endpoints, basePath, validator, successMessage, onSuccess); } - public static RouteGroupBuilder MapFormValidation( + public static RouteGroupBuilder MapFormValidation( this IEndpointRouteBuilder endpoints, string basePath, Func onSuccess,