static ObjectValue CreateNode (EvaluationContext ctx, IObjectSource objectSource, object type, object obj, BindingFlags bindingFlags, string label)
		{
			FilteredMembersSource src = new FilteredMembersSource (ctx, objectSource, type, obj, bindingFlags);
			src.Connect ();
			ObjectValue val = ObjectValue.CreateObject (src, new ObjectPath (label), "", "", ObjectValueFlags.Group|ObjectValueFlags.ReadOnly|ObjectValueFlags.NoRefresh, null);
			val.ChildSelector = "";
			return val;
		}
        static ObjectValue CreateNode(EvaluationContext ctx, IObjectSource objectSource, object type, object obj, BindingFlags bindingFlags, string label)
        {
            FilteredMembersSource src = new FilteredMembersSource(ctx, objectSource, type, obj, bindingFlags);

            src.Connect();
            ObjectValue val = ObjectValue.CreateObject(src, new ObjectPath(label), "", "", ObjectValueFlags.Group | ObjectValueFlags.ReadOnly | ObjectValueFlags.NoRefresh, null);

            val.ChildSelector = "";
            return(val);
        }
Пример #3
0
        public virtual ObjectValue[] GetObjectValueChildren(EvaluationContext ctx, IObjectSource objectSource, object type, object obj, int firstItemIndex, int count, bool dereferenceProxy)
        {
            if (IsArray(ctx, obj))
            {
                ArrayElementGroup agroup = new ArrayElementGroup(ctx, CreateArrayAdaptor(ctx, obj));
                return(agroup.GetChildren(ctx.Options));
            }

            if (IsPrimitive(ctx, obj))
            {
                return(new ObjectValue[0]);
            }

            bool showRawView = false;

            // If there is a proxy, it has to show the members of the proxy
            object proxy = obj;

            if (dereferenceProxy)
            {
                proxy = GetProxyObject(ctx, obj);
                if (proxy != obj)
                {
                    type        = GetValueType(ctx, proxy);
                    showRawView = true;
                }
            }

            TypeDisplayData tdata = GetTypeDisplayData(ctx, type);
            bool            groupPrivateMembers = ctx.Options.GroupPrivateMembers && (ctx.Options.GroupUserPrivateMembers || IsExternalType(ctx, type));

            List <ObjectValue> values           = new List <ObjectValue> ();
            BindingFlags       flattenFlag      = ctx.Options.FlattenHierarchy ? (BindingFlags)0 : BindingFlags.DeclaredOnly;
            BindingFlags       nonNonPublicFlag = groupPrivateMembers || showRawView ? (BindingFlags)0 : BindingFlags.NonPublic;
            BindingFlags       staticFlag       = ctx.Options.GroupStaticMembers ? (BindingFlags)0 : BindingFlags.Static;
            BindingFlags       access           = BindingFlags.Public | BindingFlags.Instance | flattenFlag | nonNonPublicFlag | staticFlag;

            // Load all members to a list before creating the object values,
            // to avoid problems with objects being invalidated due to evaluations in the target,
            List <ValueReference> list = new List <ValueReference> ();

            list.AddRange(GetMembersSorted(ctx, objectSource, type, proxy, access));

            object tdataType = type;

            foreach (ValueReference val in list)
            {
                try {
                    object decType = val.DeclaringType;
                    if (decType != null && decType != tdataType)
                    {
                        tdataType = decType;
                        tdata     = GetTypeDisplayData(ctx, decType);
                    }
                    DebuggerBrowsableState state = tdata.GetMemberBrowsableState(val.Name);
                    if (state == DebuggerBrowsableState.Never)
                    {
                        continue;
                    }

                    if (state == DebuggerBrowsableState.RootHidden && dereferenceProxy)
                    {
                        object ob = val.Value;
                        if (ob != null)
                        {
                            values.Clear();
                            values.AddRange(GetObjectValueChildren(ctx, val, ob, -1, -1));
                            showRawView = true;
                            break;
                        }
                    }
                    else
                    {
                        ObjectValue oval = val.CreateObjectValue(true);
                        values.Add(oval);
                    }
                }
                catch (Exception ex) {
                    ctx.WriteDebuggerError(ex);
                    values.Add(ObjectValue.CreateError(null, new ObjectPath(val.Name), GetDisplayTypeName(GetTypeName(ctx, val.Type)), ex.Message, val.Flags));
                }
            }

            if (showRawView)
            {
                values.Add(RawViewSource.CreateRawView(ctx, objectSource, obj));
            }
            else
            {
                if (IsArray(ctx, proxy))
                {
                    ICollectionAdaptor col    = CreateArrayAdaptor(ctx, proxy);
                    ArrayElementGroup  agroup = new ArrayElementGroup(ctx, col);
                    ObjectValue        val    = ObjectValue.CreateObject(null, new ObjectPath("Raw View"), "", "", ObjectValueFlags.ReadOnly, values.ToArray());
                    values = new List <ObjectValue> ();
                    values.Add(val);
                    values.AddRange(agroup.GetChildren(ctx.Options));
                }
                else
                {
                    if (ctx.Options.GroupStaticMembers && HasMembers(ctx, type, proxy, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | flattenFlag))
                    {
                        access = BindingFlags.Static | BindingFlags.Public | flattenFlag | nonNonPublicFlag;
                        values.Add(FilteredMembersSource.CreateStaticsNode(ctx, objectSource, type, proxy, access));
                    }
                    if (groupPrivateMembers && HasMembers(ctx, type, proxy, BindingFlags.Instance | BindingFlags.NonPublic | flattenFlag | staticFlag))
                    {
                        values.Add(FilteredMembersSource.CreateNonPublicsNode(ctx, objectSource, type, proxy, BindingFlags.Instance | BindingFlags.NonPublic | flattenFlag | staticFlag));
                    }

                    if (!ctx.Options.FlattenHierarchy)
                    {
                        object baseType = GetBaseType(ctx, type, false);
                        if (baseType != null)
                        {
                            values.Insert(0, BaseTypeViewSource.CreateBaseTypeView(ctx, objectSource, baseType, proxy));
                        }
                    }
                }
            }
            return(values.ToArray());
        }
        public override ObjectValue[] GetChildren(ObjectPath path, int index, int count, EvaluationOptions options)
        {
            EvaluationContext ctx = GetContext(options);

            try
            {
                List <ObjectValue> list        = new List <ObjectValue> ();
                BindingFlags       flattenFlag = options.FlattenHierarchy ? (BindingFlags)0 : BindingFlags.DeclaredOnly;
                BindingFlags       flags       = BindingFlags.Static | BindingFlags.Public | flattenFlag;
                bool groupPrivateMembers       = options.GroupPrivateMembers && (options.GroupUserPrivateMembers || ctx.Adapter.IsExternalType(ctx, type));
                if (!groupPrivateMembers)
                {
                    flags |= BindingFlags.NonPublic;
                }

                TypeDisplayData tdata     = ctx.Adapter.GetTypeDisplayData(ctx, type);
                object          tdataType = type;

                foreach (ValueReference val in ctx.Adapter.GetMembersSorted(ctx, this, type, null, flags))
                {
                    object decType = val.DeclaringType;
                    if (decType != null && decType != tdataType)
                    {
                        tdataType = decType;
                        tdata     = ctx.Adapter.GetTypeDisplayData(ctx, decType);
                    }
                    DebuggerBrowsableState state = tdata.GetMemberBrowsableState(val.Name);
                    if (state == DebuggerBrowsableState.Never)
                    {
                        continue;
                    }

                    ObjectValue oval = val.CreateObjectValue(options);
                    list.Add(oval);
                }

                List <ObjectValue> nestedTypes = new List <ObjectValue> ();
                foreach (object t in ctx.Adapter.GetNestedTypes(ctx, type))
                {
                    nestedTypes.Add(new TypeValueReference(ctx, t).CreateObjectValue(options));
                }

                nestedTypes.Sort(delegate(ObjectValue v1, ObjectValue v2)
                {
                    return(v1.Name.CompareTo(v2.Name));
                });

                list.AddRange(nestedTypes);

                if (groupPrivateMembers)
                {
                    list.Add(FilteredMembersSource.CreateNonPublicsNode(ctx, this, type, null, BindingFlags.NonPublic | BindingFlags.Static | flattenFlag));
                }

                if (!options.FlattenHierarchy)
                {
                    object baseType = ctx.Adapter.GetBaseType(ctx, type, false);
                    if (baseType != null)
                    {
                        TypeValueReference baseRef = new TypeValueReference(ctx, baseType);
                        ObjectValue        baseVal = baseRef.CreateObjectValue(false);
                        baseVal.Name = "base";
                        list.Insert(0, baseVal);
                    }
                }

                return(list.ToArray());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                ctx.WriteDebuggerOutput(ex.Message);
                return(new ObjectValue [0]);
            }
        }
        public override ObjectValue[] GetChildren(ObjectPath path, int index, int count, EvaluationOptions options)
        {
            var ctx = GetContext(options);

            try {
                BindingFlags flattenFlag         = options.FlattenHierarchy ? (BindingFlags)0 : BindingFlags.DeclaredOnly;
                BindingFlags flags               = BindingFlags.Static | BindingFlags.Public | flattenFlag;
                bool         groupPrivateMembers = options.GroupPrivateMembers || ctx.Adapter.IsExternalType(ctx, type);
                var          list = new List <ObjectValue> ();

                if (!groupPrivateMembers)
                {
                    flags |= BindingFlags.NonPublic;
                }

                var tdata     = ctx.Adapter.GetTypeDisplayData(ctx, type);
                var tdataType = type;

                foreach (var val in ctx.Adapter.GetMembersSorted(ctx, this, type, null, flags))
                {
                    var decType = val.DeclaringType;
                    if (decType != null && decType != tdataType)
                    {
                        tdataType = decType;
                        tdata     = ctx.Adapter.GetTypeDisplayData(ctx, decType);
                    }

                    var state = tdata.GetMemberBrowsableState(val.Name);
                    if (state == DebuggerBrowsableState.Never)
                    {
                        continue;
                    }

                    var oval = val.CreateObjectValue(options);
                    list.Add(oval);
                }

                var nestedTypes = new List <ObjectValue> ();
                foreach (var nestedType in ctx.Adapter.GetNestedTypes(ctx, type))
                {
                    nestedTypes.Add(new TypeValueReference(ctx, nestedType).CreateObjectValue(options));
                }

                nestedTypes.Sort((v1, v2) => string.Compare(v1.Name, v2.Name, StringComparison.CurrentCulture));

                list.AddRange(nestedTypes);

                if (groupPrivateMembers)
                {
                    list.Add(FilteredMembersSource.CreateNonPublicsNode(ctx, this, type, null, BindingFlags.NonPublic | BindingFlags.Static | flattenFlag));
                }

                if (!options.FlattenHierarchy)
                {
                    object baseType = ctx.Adapter.GetBaseType(ctx, type, false);
                    if (baseType != null)
                    {
                        var baseRef = new TypeValueReference(ctx, baseType);
                        var baseVal = baseRef.CreateObjectValue(false);
                        baseVal.Name = "base";
                        list.Insert(0, baseVal);
                    }
                }

                return(list.ToArray());
            } catch (Exception ex) {
                ctx.WriteDebuggerOutput(ex.Message);
                return(new ObjectValue [0]);
            }
        }