Beispiel #1
0
 public KoNodeStatus GetStatus(RenderNode node)
 {
     return _map[node.Instance];
 }
Beispiel #2
0
        private RenderNode RegisterItem(object instance, RenderNode dependent)
        {
            if (instance == null)
                return null;

            RenderNode result;
            if (!_items.TryGetValue(instance, out result))
            {
                IEnumerable<object> elements;
                switch (_strategy.ClassifyInstance(instance, out elements))
                {
                    case InstanceType.Object:
                        result = new ObjectOrValueNode(instance, _nextId++, false);
                        break;
                    case InstanceType.Value:
                        result = new ObjectOrValueNode(instance, _nextId++, true);
                        break;
                    case InstanceType.Link:
                        result = new LinkNode(instance, _nextId++);
                        break;
                    case InstanceType.Collection:
                        var collection = new CollectionNode(instance, _nextId++);
                        result = collection;
                        collection.Elements.AddRange(elements.Select(x => RegisterItem(x, result)));
                        break;
                }

                if (result != null)
                {
                    _items[instance] = result;
                    _newItems.Enqueue(result);
                }
            }
            if (result != null && dependent != null) // TODO: consider requiring non null
            {
                result.Dependents.Add(dependent);
                dependent.Dependencies.Add(result);
            }
            return result;
        }
Beispiel #3
0
 protected void SerializeElement(RenderNode element)
 {
     if (element.Dependents.Count > 1)
     {
         Writer.Write(string.Format("{0}", element.RenderedName));
     }
     else
     {
         Serialize(element);
     }
 }
Beispiel #4
0
 public KoNodeStatus(RenderNode node, bool isCommon)
 {
     Node = node;
     IsCommon = isCommon;
 }
Beispiel #5
0
 public string RenderValue(RenderNode node)
 {
     if (node is ObjectOrValueNode)
         return RenderValue((ObjectOrValueNode) node);
     if (node is LinkNode)
         return RenderValue((LinkNode) node);
     if (node is CollectionNode)
         return RenderValue((CollectionNode) node);
     throw new NotSupportedException();
 }
Beispiel #6
0
 public string Render(RenderNode node)
 {
     if (node == null)
         return "null";
     var status = _renderSchedule.GetStatus(node);
     if (status.IsCommon && status.HasEmitted)
         return status.RenderName;
     return RenderValue(node);
 }
Beispiel #7
0
 private static bool IsCommon(RenderNode node)
 {
     return
         !(node is ObjectOrValueNode && ((ObjectOrValueNode)node).TreatAsValue) &&
         (node.Dependents.Count > 1 || node.Dependents.Any(y => y is LinkNode));
 }