1using System.Linq.Expressions;
2using System.Reflection;
11 public record
class Result(string Name,
ISerializer Serializer, Type Type);
12 private static Result R(
string name,
ISerializer ser, Type ty) =>
new Result(name, ser, ty);
14 public Result? FieldLookup(PropertyInfo prop, Expression callee)
16 if (Ctx.TryGetBaseType(callee.Type, out var info))
18 var field = info.Fields.FirstOrDefault(f => f.Property == prop);
19 return field is
null ? null : R(field.Name, field.Serializer, field.Type);
22 return Table(prop, callee);
25 public Result? MethodLookup(MethodInfo method, Expression callee) =>
26 Table(method, callee);
28 public bool HasField(PropertyInfo prop, Expression callee) =>
29 FieldLookup(prop, callee) is not
null;
31 public bool HasMethod(MethodInfo method, Expression callee) =>
32 MethodLookup(method, callee) is not
null;
37 private Result? Table(MemberInfo member, Expression callee) =>
38 callee.Type.Name
switch
40 "string" => StringTable(member, callee),
44 private Result? StringTable(MemberInfo member, Expression callee) =>
47 "Length" => R(
"length", Serializer.Generate<
int>(Ctx), typeof(
int)),
48 "EndsWith" => R(
"endsWith", Serializer.Generate<
bool>(Ctx), typeof(
int)),
49 "StartsWith" => R(
"startsWith", Serializer.Generate<
bool>(Ctx), typeof(
int)),
A class representing the mapping context to be used during serialization and deserialization.
A generic interface that defines serialize and deserialize behavior for a specific type,...