4using System.Linq.Expressions;
5using System.Reflection;
12 public record
class Result(string Name,
IDeserializer Deserializer, Type Type);
13 private static Result R(
string name,
IDeserializer deser, Type ty) =>
new Result(name, deser, ty);
15 public Result? FieldLookup(PropertyInfo prop, Expression callee)
17 if (Ctx.TryGetBaseType(callee.Type, out var info))
19 var field = info.Fields.FirstOrDefault(f => f.Property == prop);
20 return field is
null ? null : R(field.Name, field.Deserializer, field.Type);
23 return Table(prop, callee);
26 public Result? MethodLookup(MethodInfo method, Expression callee) =>
27 Table(method, callee);
29 public bool HasField(PropertyInfo prop, Expression callee) =>
30 FieldLookup(prop, callee) is not
null;
32 public bool HasMethod(MethodInfo method, Expression callee) =>
33 MethodLookup(method, callee) is not
null;
38 private Result? Table(MemberInfo member, Expression callee) =>
39 callee.Type.Name
switch
41 "string" => StringTable(member, callee),
45 private Result? StringTable(MemberInfo member, Expression callee) =>
48 "Length" => R(
"length", Deserializer.Generate<
int>(Ctx), typeof(
int)),
49 "EndsWith" => R(
"endsWith", Deserializer.Generate<
bool>(Ctx), typeof(
int)),
50 "StartsWith" => R(
"startsWith", Deserializer.Generate<
bool>(Ctx), typeof(
int)),