public bool Process(object?instance, Type instanceType, IObjectDumperResultBuilder builder, int indent, int currentDepth)
    {
        if (instance is ContextDictionary contextClass)
        {
            builder.BeginNesting(indent, instanceType);
            builder.BeginComplexType(indent, instanceType);


            builder.AddEnumerableItem(true, indent, true);
            builder.AddName(indent, nameof(ContextDictionary.Custom1));
            Callback?.Process(contextClass.Custom1, typeof(string), builder, indent + 4, currentDepth + 1);
            builder.AddEnumerableItem(false, indent, true);
            builder.AddName(indent, nameof(ContextDictionary.Custom2));
            Callback?.Process(contextClass.Custom2, typeof(int), builder, indent + 4, currentDepth + 1);

            foreach (var item in contextClass)
            {
                builder.AddEnumerableItem(false, indent, false);
                Callback?.Process(item, item.GetType() ?? instanceType.GetGenericArguments()[0], builder, indent + 4, currentDepth + 1);
            }

            builder.EndComplexType(false, indent, instanceType);

            return(true);
        }

        return(false);
    }
Exemple #2
0
    public bool Process(object?instance, Type instanceType, IObjectDumperResultBuilder builder, int indent, int currentDepth)
    {
        if (instance == null)
        {
            return(false);
        }

        builder.BeginNesting(indent, instanceType);
        builder.BeginComplexType(indent, instanceType);

        var first = IterateChildren
                    (
            new ComplexTypeDumperState
            (
                true,
                builder,
                indent,
                currentDepth
            ),
            () => Callback?.GetProperties(instance),
            property => ((PropertyDescriptor)property).Name,
            property => ((PropertyDescriptor)property).GetValue(instance),
            property => ((PropertyDescriptor)property).PropertyType
                    );

        first = IterateChildren
                (
            new ComplexTypeDumperState
            (
                first,
                builder,
                indent,
                currentDepth
            ),
            () => Callback?.GetFields(instance),
            property => ((FieldInfo)property).Name,
            property => ((FieldInfo)property).GetValue(instance),
            property => ((FieldInfo)property).FieldType
                );

        builder.EndComplexType(first, indent, instanceType);

        return(true);
    }