public static TypeContext <S> WalkExpression <T, S>(TypeContext <T> tc, Expression <Func <T, S> > lambda) { var mag = new MemberAccessGatherer() { replacements = { { lambda.Parameters[0], new TypeContextExpression(new PropertyInfo[0], typeof(T), tc.PropertyRoute, tc.Value) } } }; TypeContextExpression result = Cast(mag.Visit(lambda.Body)); var value = result.Value == NonValue ? (S)(object)null : (S)result.Value; return(new TypeContext <S>(value, tc, result.Properties.ToString(a => a.Name, TypeContext.Separator), result.Route)); }
public override MList <S> GetValue(MappingContext <MList <S> > ctx) { using (HeavyProfiler.LogNoStackTrace("GetValue", () => "MListDictionaryMapping<{0}>".FormatWith(typeof(S).TypeName()))) { if (ctx.Empty()) { return(ctx.None()); } MList <S> list = ctx.Value; var dic = (FilterElements == null ? list : list.Where(FilterElements)).ToDictionary(GetKey); PropertyRoute route = ctx.PropertyRoute.Add("Item").Continue(MemberList); string[] namesToAppend = MemberList.Select(MemberAccessGatherer.GetName).NotNull().ToArray(); foreach (MappingContext <S> itemCtx in GenerateItemContexts(ctx)) { var tce = new TypeContextExpression(new PropertyInfo[0], typeof(S), itemCtx.PropertyRoute, itemCtx.Value); SubContext <K> subContext = new SubContext <K>(TypeContextUtilities.Compose(itemCtx.Prefix, namesToAppend), null, route, itemCtx); subContext.Value = KeyMapping(subContext); if (!dic.ContainsKey(subContext.Value) && OnlyIfPossible) { continue; } itemCtx.Value = dic.GetOrThrow(subContext.Value); itemCtx.Value = ElementMapping(itemCtx); ctx.AddChild(itemCtx); } return(list); } }