Exemple #1
0
        public void Evaluate()
        {
            var parent = (MemberNode)Parent;

            object[] items = LocalsHelper.AsObjectArrayFromIenumerable(parent.Object);
            if (items != null)
            {
                List = items;
            }

            if (Offset + Count > items.Length)
            {
                Count = items.Length - Offset;
            }

            for (int i = Offset; i < Offset + Count; i++)
            {
                var itemValue = List[i];
                var typeName  = itemValue == null ? "" : itemValue.GetType().ToSignatureString();


                if (i - Offset < Nodes.Count)
                {
                    var n        = (MemberNode)Nodes[i - Offset];
                    var oldValue = n.Object;
                    n.Object     = List[i];
                    n.ObjectType = List[i] == null ? null : List[i].GetType();

                    n[1] = List[i];
                    n[2] = typeName;

                    n.Changed = !object.Equals(oldValue, n.Object);
                }
                else
                {
                    MemberNode item = new MemberNode("[" + i + "]", List[i], typeName)
                    {
                        ObjectType = itemValue == null ? null : itemValue.GetType(),
                        Object     = itemValue,
                        Member     = null,
                        Changed    = true
                    };
                    item.HasChildren = true;
                    this.Nodes.Add(item);
                }
            }
        }
        public virtual void ExpandMembers(bool showControls, bool showFields, bool showProperties)
        {
            if (Object == null)
            {
                return;
            }



            Nodes.Clear();

            if (ObjectType.BaseType != null && (ObjectType.BaseType != typeof(object) && ObjectType.BaseType != typeof(System.ValueType)))
            {
                MemberNode n = new MemberNode("(base)", "", ObjectType.BaseType)
                {
                    ObjectType = ObjectType.BaseType,
                    Object     = Object,
                    Member     = null
                };
                n.ImageId = (int)IconEnum.PublicField;

                if (CanExpandNodeWithType(n.ObjectType))
                {
                    n.HasChildren = true;
                }

                Nodes.Add(n);
            }

            var events = ObjectType.GetEventsOfType(true, false);

            if (events.Count > 0)
            {
                MemberNode n = new MemberNode("(all wired events)", "", ObjectType)
                {
                    ObjectType = ObjectType,
                    Object     = Object,
                    Member     = null
                };
                n.ImageId = (int)IconEnum.PublicEvent;

                foreach (var ev in events)
                {
                    EventNode eventNode = new EventNode(ev, Object);
                    eventNode.ExpandMembers();

                    // add if has wired events
                    if (eventNode.Nodes.Count > 0)
                    {
                        n.Nodes.Add(eventNode);
                    }
                }

                Nodes.Add(n);
            }

            if (ObjectType != typeof(string))
            {
                try
                {
                    object[] array = LocalsHelper.AsObjectArrayFromIenumerable(Object);
                    if (array != null)
                    {
                        AddIEnumerableNodes(array);
                    }

                    //var ienumerableInterface = ObjectType.GetInterfaces().Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable<>)).FirstOrDefault();
                    //if (ienumerableInterface != null)
                    //{
                    //    object[] items = LocalsHelper.AsObjectArrayFromGenericIenumerable(Object);
                    //    AddIEnumerableNodes(items);
                    //}
                    //else
                    //{
                    //    var ienumerableNonGenericInterface = ObjectType.GetInterfaces().Where(i => i.IsAssignableFrom(typeof(IEnumerable))).FirstOrDefault();
                    //    if (ienumerableInterface != null)
                    //    {
                    //        object[] items = LocalsHelper.AsObjectArrayFromIenumerable(Object);
                    //        AddIEnumerableNodes(items);
                    //    }
                    //    else
                    //    {
                    //        var icollection = ObjectType.GetInterfaces().Where(i => i.IsAssignableFrom(typeof(ICollection))).FirstOrDefault();
                    //        if (icollection != null)
                    //        {
                    //            object[] items = LocalsHelper.AsObjectArrayFromIenumerable(Object);
                    //            AddIEnumerableNodes(items);
                    //        }

                    //    }
                    //}
                }
                catch (Exception)
                {
                }
            }

            foreach (var f in ObjectType.GetFieldsOfType(false, false)
                     .OrderBy(f => f.Name))
            {
                if (!f.Name.Contains(">k__BackingField"))
                {
                    MemberNode n = new MemberNode(f);
                    AddNode(this, n, showControls, showFields, showProperties);
                }
            }

            foreach (var p in ObjectType.GetPropertiesOfType(false, true)
                     .Where(p => p.GetIndexParameters().Length <= 0)
                     .OrderBy(p => p.Name))
            {
                MemberNode n = new MemberNode(p);
                AddNode(this, n, showControls, showFields, showProperties);
            }

            foreach (var ev in ObjectType.GetEventsOfType(false, true)
                     .OrderBy(e => e.Name))
            {
                EventNode n = new EventNode(ev, null);
                this.Nodes.Add(n);
                n.ExpandMembers();
            }

            if (Nodes.Count <= 0)
            {
                HasChildren = false;
            }
        }