Beispiel #1
0
        protected override void AssembleFromChildren(MemberAssignment a, ConstructionNode constructionNode,
                                                     INodeToObjectBuilder nodeToObjectBuilder, BuilderContext context)
        {
            var loaderInfo = metadataProvider.Get(constructionNode.ActualInstanceType).FragmentLoaderInfo;

            if (loaderInfo != null)
            {
                if (constructionNode.ActualInstanceType == loaderInfo.Type &&
                    a.Member.MemberName == loaderInfo.PropertyName)
                {
                    ConstructionNode payload = constructionNode.Assignments.First(assignment => assignment.Member.MemberName == loaderInfo.PropertyName).Values.First();
                    var loader = loaderInfo.Loader.Load(payload, nodeToObjectBuilder, context);
                    CreateInstance(constructionNode);
                    ApplyAssignments(constructionNode, nodeToObjectBuilder, context);
                    a.Values = new[] { new ConstructionNode(loader.GetType())
                                       {
                                           Instance = loader
                                       } };
                    AssigmentApplier.ExecuteAssignment(new NodeAssignment(a, constructionNode.Instance), nodeToObjectBuilder, context);
                }
            }
            else
            {
                base.AssembleFromChildren(a, constructionNode, nodeToObjectBuilder, context);
            }
        }
Beispiel #2
0
 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);
     }
 }
Beispiel #3
0
 public void ExecuteAssignment(NodeAssignment assignment, INodeToObjectBuilder builder, BuilderContext context)
 {
     if (!assignment.Assignment.Member.MemberType.IsCollection())
     {
         AssignSingleValue(assignment, builder, context);
     }
     else
     {
         AssignCollection(assignment);
     }
 }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        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 TemplateContent(ConstructionNode node, INodeToObjectBuilder builder, BuilderContext context)
 {
     this.node    = node;
     this.builder = builder;
     this.context = context;
 }
Beispiel #9
0
 protected abstract void HandleCore(object parent, Member member, MutablePipelineUnit mutable, INodeToObjectBuilder builder, BuilderContext context);
Beispiel #10
0
 public void Handle(object parent, Member member, MutablePipelineUnit mutable, INodeToObjectBuilder builder, BuilderContext context)
 {
     if (!mutable.Handled)
     {
         pipeline.Handle(parent, member, mutable, builder, context);
         HandleCore(parent, member, mutable, builder, context);
     }
 }
Beispiel #11
0
        protected override void HandleCore(object parent, Member member, MutablePipelineUnit mutable, INodeToObjectBuilder builder, BuilderContext context)
        {
            var od = mutable.Value as ObserveDefinition;
            var bd = mutable.Value as BindDefinition;

            if (od != null)
            {
                //BindToObservable(od);
            }
            else if (bd != null)
            {
                if (bd.TargetInstance is IPropertyHost)
                {
                    ClearExistingBinding(bd);
                    var bindingSubscription = BindToProperty(context, bd);
                    AddExistingBinding(bd, bindingSubscription);
                }

                mutable.Handled = true;
            }
        }
Beispiel #12
0
        protected override void HandleCore(object parent, Member member, MutablePipelineUnit mutable, INodeToObjectBuilder builder, BuilderContext context)
        {
            var deferringLoader = metadataProvider.Get(parent.GetType()).FragmentLoaderInfo;

            if (deferringLoader == null)
            {
                return;
            }

            if (IsApplicable(deferringLoader, parent, member))
            {
                mutable.Value = deferringLoader.Loader.Load(mutable.ParentNode, builder, context);
            }
        }
 public void Handle(object parent, Member member, MutablePipelineUnit mutable, INodeToObjectBuilder builder, BuilderContext context)
 {
 }
Beispiel #14
0
 protected virtual void AssembleFromChildren(MemberAssignment a, ConstructionNode constructionNode, INodeToObjectBuilder nodeToObjectBuilder, BuilderContext context)
 {
     foreach (var node in a.Values)
     {
         Assemble(node, nodeToObjectBuilder, constructionNode, context);
     }
 }
 public void ExecuteAssignment(NodeAssignment assignment, INodeToObjectBuilder builder, BuilderContext context)
 {
     func(assignment, builder, context);
 }
Beispiel #16
0
 public void Assemble(ConstructionNode node, INodeToObjectBuilder nodeToObjectBuilder, ConstructionNode parent = null, BuilderContext context = null)
 {
     assembler.Assemble(node, nodeToObjectBuilder, parent, context);
     assembler.Assemble(node, nodeToObjectBuilder, parent, context);
 }
Beispiel #17
0
        protected override void HandleCore(object parent, Member member, MutablePipelineUnit mutable, INodeToObjectBuilder builder, BuilderContext context)
        {
            var extension = mutable.Value as IMarkupExtension;

            if (extension != null)
            {
                var keyedInstance = new KeyedInstance(parent);
                var assignment    = new Assignment(keyedInstance, member, mutable.Value);
                var finalValue    = extension.GetValue(new ExtensionValueContext(assignment, null, null, null));
                mutable.Value = finalValue;
            }
        }
Beispiel #18
0
 public TemplateContent(ConstructionNode node, INodeToObjectBuilder builder)
 {
     this.node    = node;
     this.builder = builder;
 }
 public object Load(ConstructionNode node, INodeToObjectBuilder builder, BuilderContext context)
 {
     return(new TemplateContent(node, builder, context));
 }
Beispiel #20
0
 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);
     }
 }