private ListTarget GetListTarget(ListResult result, IBindingMetadata metadata, KeyReader joinKey) { int bufferIndex = this.Buffer.GetListIndex(metadata, joinKey?.Reference); metadata = joinKey?.Target ?? metadata; ListTarget target = result.Targets.FirstOrDefault(t => t.Index == bufferIndex); if (target != null) { return(target); } target = new ListTarget() { Index = bufferIndex, Variable = this.GetListVariable(metadata, joinKey), }; if (joinKey == null && metadata.HasFlag(BindingMetadataFlags.Item)) { target.NewList = target.NewTarget = metadata.Parent.Composition?.Construct ?? throw BindingException.InvalidConstructor(metadata.Parent); target.AddMethod = metadata.Parent.Composition.Add; } if (joinKey != null) { target.NewTarget = Expression.New(target.Variable.Type); } if (target.NewTarget != null) { result.Targets.Add(target); } return(target); }
private ParameterExpression GetListVariable(IBindingMetadata metadata, KeyReader joinKey) { if (joinKey != null) { Type dictType = typeof(Dictionary <,>).MakeGenericType(joinKey.KeyType, typeof(ElasticArray)); return(this.GetNamedVariable(dictType, metadata.Identity)); } else if (metadata.HasFlag(BindingMetadataFlags.Item)) { Type listType = metadata.Parent.Composition?.Construct?.Type ?? throw BindingException.InvalidConstructor(metadata.Parent); return(this.GetNamedVariable(listType, metadata.Identity)); } return(null); }