forked from CodeBeamOrg/UltimateAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConventionResolver.cs
More file actions
24 lines (20 loc) · 794 Bytes
/
ConventionResolver.cs
File metadata and controls
24 lines (20 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System.Linq.Expressions;
namespace CodeBeam.UltimateAuth.Credentials.EntityFrameworkCore
{
internal static class ConventionResolver
{
public static Expression<Func<TUser, TProp>>? TryResolve<TUser, TProp>(params string[] names)
{
var prop = typeof(TUser)
.GetProperties()
.FirstOrDefault(p =>
names.Contains(p.Name, StringComparer.OrdinalIgnoreCase) &&
typeof(TProp).IsAssignableFrom(p.PropertyType));
if (prop is null)
return null;
var param = Expression.Parameter(typeof(TUser), "u");
var body = Expression.Property(param, prop);
return Expression.Lambda<Func<TUser, TProp>>(body, param);
}
}
}