Exemplo n.º 1
0
        private void UpdateItem(ObjectOrValueNode node, MetadataInfo info)
        {
            var newInstance = info.GetValue(node.Instance);

            if (newInstance == null)
            {
                node.Metadata[info] = null;
            }
            else
            {
                var newItem = RegisterItem(newInstance, node);
                node.Metadata[info] = newItem;
            }
        }
Exemplo n.º 2
0
 private void AnalyzeItem(ObjectOrValueNode node)
 {
     foreach (var p in _typeMemberRequirements.Where(p => p.Key.IsAssignableFrom(node.Instance.GetType())).SelectMany(v => v.Value))
     {
         UpdateItem(node, p);
     }
 }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
        protected string RenderValue(ObjectOrValueNode node)
        {
            var status = _renderSchedule.GetStatus(node);
            status.HasEmitted = true;

            var subject = node.Instance;

            if (subject is string)
            {
                return subject.ToSingleQuotedJsString();
            }
            if (subject is bool)
            {
                return ((bool) subject) ? "true" : "false";
            }
            if (subject is byte
                || subject is sbyte
                || subject is short
                || subject is ushort
                || subject is int
                || subject is uint
                || subject is long
                || subject is ulong
                || subject is float
                || subject is double
                || subject is decimal)
            {
                return subject.ToString();
            }
            if (subject is Enum)
            {
                return Convert.ChangeType(subject, Enum.GetUnderlyingType(subject.GetType())).ToString();
            }

            var memberlist = node.Members.Select(RenderMember).ToList();
            if (node.Metadata.Count > 0)
            {
                memberlist.Add(string.Format("__md: {{{0}}}", node.Metadata.Select(RenderMember)).Delimit(","));
            }
            return string.Format("{{{0}}}", memberlist.Delimit(","));
        }