Upgrading to net10 and getting ready for AOT even though AOT is currently not available for RazorPages.
This commit is contained in:
@@ -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<TModel>(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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user