public override T GetValue(MappingContext <T> ctx) { using (HeavyProfiler.LogNoStackTrace("GetValue", () => "EntityMapping<{0}>".FormatWith(typeof(T).TypeName()))) { if (ctx.Empty()) { return(ctx.None()); } var val = GetEntity(ctx); if (val == ctx.Value) { ctx.SupressChange = true; } else { ctx.Value = val; } SetValueProperties(ctx); return(val); } }
public override T GetValue(MappingContext <T> ctx) { using (HeavyProfiler.LogNoStackTrace("GetValue", () => "AutoEntityMapping<{0}>".FormatWith(typeof(T).TypeName()))) { if (ctx.Empty()) { return(ctx.None()); } Type entityType; entityType = GetRuntimeType(ctx); if (entityType == null) { return((T)(object)null); } if (typeof(T) == entityType || typeof(T).IsEmbeddedEntity()) { return(GetRuntimeValue <T>(ctx, ctx.PropertyRoute)); } return(miGetRuntimeValue.GetInvoker(entityType)(this, ctx, PropertyRoute.Root(entityType))); } }
public Lite <S> GetValue(MappingContext <Lite <S> > ctx) { using (HeavyProfiler.LogNoStackTrace("GetValue", () => "LiteMapping<{0}>".FormatWith(typeof(S).TypeName()))) { if (ctx.Empty()) { return(ctx.None()); } var newLite = Change(ctx); if (newLite == ctx.Value) { ctx.SupressChange = true; } return(newLite); } }
public R GetRuntimeValue <R>(MappingContext <T> ctx, PropertyRoute route) where R : class, T { if (AllowedMappings != null && !AllowedMappings.ContainsKey(typeof(R))) { return((R)(object)ctx.None(ValidationMessage.Type0NotAllowed.NiceToString().FormatWith(typeof(R)))); } Mapping <R> mapping = (Mapping <R>)(AllowedMappings?.TryGetC(typeof(R)) ?? Navigator.EntitySettings(typeof(R)).UntypedMappingLine); SubContext <R> sc = new SubContext <R>(ctx.Prefix, null, route, ctx) { Value = ctx.Value as R }; // If the type is different, the AutoEntityMapping has the current value but EntityMapping just null sc.Value = mapping(sc); ctx.SupressChange = sc.SupressChange; ctx.AddChild(sc); return(sc.Value); }
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); } }
public override MList <S> GetValue(MappingContext <MList <S> > ctx) { using (HeavyProfiler.LogNoStackTrace("GetValue", () => "MListMapping<{0}>".FormatWith(typeof(S).TypeName()))) { if (ctx.Empty()) { return(ctx.None()); } IMListPrivate <S> mlistPriv = ctx.Value; var dic = mlistPriv == null ? new Dictionary <PrimaryKey, MList <S> .RowIdElement>() : mlistPriv.InnerList.Where(a => a.RowId.HasValue).ToDictionary(a => a.RowId.Value, a => a); var newList = new List <MList <S> .RowIdElement>(); foreach (MappingContext <S> itemCtx in GenerateItemContexts(ctx)) { Debug.Assert(!itemCtx.Empty()); string rowIdString = (itemCtx.Inputs.ContainsKey(EntityListBaseKeys.RowId)? itemCtx.Inputs[EntityListBaseKeys.RowId]:null); if (rowIdString.HasText()) { var rowId = new PrimaryKey((IComparable)ReflectionTools.Parse(rowIdString, GetRowIdType(ctx))); var oldValue = dic.GetOrThrow(rowId, "No RowID {0} found"); itemCtx.Value = oldValue.Element; itemCtx.Value = ElementMapping(itemCtx); ctx.AddChild(itemCtx); if (itemCtx.Value != null) { var val = itemCtx.SupressChange ? oldValue.Element : itemCtx.Value; if (oldValue.Element.Equals(val)) { newList.Add(new MList <S> .RowIdElement(val, rowId, oldValue.OldIndex)); } else { newList.Add(new MList <S> .RowIdElement(val)); } } } else { itemCtx.Value = ElementMapping(itemCtx); ctx.AddChild(itemCtx); if (itemCtx.Value != null && !itemCtx.SupressChange) { newList.Add(new MList <S> .RowIdElement(itemCtx.Value)); } } } if (!AreEqual(newList, mlistPriv == null ? null : mlistPriv.InnerList)) { Signum.Web.Mapping.AssertCanChange(ctx.PropertyRoute); if (ctx.Value == null) { mlistPriv = ctx.Value = new MList <S>(); } var added = newList.Select(a => a.Element).Except(mlistPriv.InnerList.Select(a => a.Element)).ToList(); var removed = mlistPriv.InnerList.Select(a => a.Element).Except(newList.Select(a => a.Element)).ToList(); mlistPriv.InnerList.Clear(); mlistPriv.InnerList.AddRange(newList); mlistPriv.InnerListModified(added, removed); } return(ctx.Value); } }