private void AssignSingleValue(NodeAssignment assignment, INodeToObjectBuilder builder, BuilderContext context) { var children = assignment.Assignment.Values.ToList(); if (children.Count > 1) { throw new InvalidOperationException($"Cannot assign multiple values to a the property {assignment}"); } var nodeBeingAssigned = children.First(); var value = nodeBeingAssigned.Instance; var assign = new Assignment(assignment.Instance, assignment.Assignment.Member, value); SetMember(assign, nodeBeingAssigned, builder, context); }
private void SetMember(Assignment assignment, ConstructionNode parentNode, INodeToObjectBuilder builder, BuilderContext context) { var mutableUnit = new MutablePipelineUnit(parentNode, assignment.Value); pipeline.Handle(assignment.Target.Instance, assignment.Member, mutableUnit, builder, context); if (mutableUnit.Handled) { return; } assignment.Member.SetValue(assignment.Target.Instance, mutableUnit.Value); }
private void AssembleAssignment(MemberAssignment memberAssignment, ConstructionNode node, INodeToObjectBuilder nodeToObjectBuilder, BuilderContext context) { if (memberAssignment.SourceValue != null) { AssembleFromSourceValue(memberAssignment, node, context); } else { AssembleFromChildren(memberAssignment, node, nodeToObjectBuilder, context); } }
public void ExecuteAssignment(NodeAssignment assignment, INodeToObjectBuilder builder, BuilderContext context) { if (!assignment.Assignment.Member.MemberType.IsCollection()) { AssignSingleValue(assignment, builder, context); } else { AssignCollection(assignment); } }
protected void ApplyAssignments(ConstructionNode node, INodeToObjectBuilder builder, BuilderContext context) { foreach (var assignment in node.Assignments) { var nodeAssignment = new NodeAssignment(assignment, node.Instance); AssigmentApplier.ExecuteAssignment(nodeAssignment, builder, context); } }
private void CreateIntermediateNode(ConstructionNode node, INodeToObjectBuilder nodeToObjectBuilder, BuilderContext context) { foreach (var a in node.Assignments) { AssembleAssignment(a, node, nodeToObjectBuilder, context); } foreach (var c in node.Children) { Assemble(c, nodeToObjectBuilder, node, context); } if (CanBeCreated(node)) { CreateInstance(node); ApplyAssignments(node, nodeToObjectBuilder, context); AttachChildren(node); } }
public void Assemble(ConstructionNode node, INodeToObjectBuilder nodeToObjectBuilder, ConstructionNode parent = null, BuilderContext context = null) { node.Parent = parent; if (node.IsCreated) { return; } if (node.SourceValue != null) { AssembleLeafNode(node, context); } else { CreateIntermediateNode(node, nodeToObjectBuilder, context); } }
private void AssembleFromSourceValue(MemberAssignment a, ConstructionNode node, BuilderContext context) { var conversionResult = Converter.Convert(a.SourceValue, a.Member.MemberType, new ConvertContext() { Node = node, BuilderContext = context }); a.Values = new List <ConstructionNode> { new ConstructionNode(a.Member.MemberType) { Instance = conversionResult.Item2, IsCreated = conversionResult.Item1, Parent = node, } }; }
protected virtual void AssembleFromChildren(MemberAssignment a, ConstructionNode constructionNode, INodeToObjectBuilder nodeToObjectBuilder, BuilderContext context) { foreach (var node in a.Values) { Assemble(node, nodeToObjectBuilder, constructionNode, context); } }