예제 #1
0
 public ComplexTypeDumperState(bool first, IObjectDumperResultBuilder builder, int indent, int currentDepth)
 {
     First        = first;
     Builder      = builder;
     Indent       = indent;
     CurrentDepth = currentDepth;
 }
    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);
    }
예제 #3
0
    public bool Process(object?instance, Type instanceType, IObjectDumperResultBuilder builder, int indent, int currentDepth)
    {
        try
        {
            foreach (var part in _parts)
            {
                if (part is IObjectDumperPartWithCallback initializer && initializer.Callback == null)
                {
                    initializer.Callback = this;
                }
                instance = part.Transform(instance, builder, indent, currentDepth);
            }

            if (!_parts.All(part => part.ShouldProcess(instance, builder, indent, currentDepth)))
            {
                return(true);
            }

            return(Array.Find(_parts, part => part.Process(instance, instanceType, builder, indent, currentDepth)) != null);
        }
        catch (Exception ex)
        {
            builder.AddException(ex);

            return(true);
        }
    }
예제 #4
0
    public bool Process(object?instance, Type instanceType, IObjectDumperResultBuilder builder, int indent, int currentDepth)
    {
        if (!(instance is string) && instance is IEnumerable enumerable)
        {
            builder.BeginNesting(indent, instanceType);
            builder.BeginEnumerable(indent, instanceType);

            var firstEnum = true;
            foreach (var item in enumerable)
            {
                builder.AddEnumerableItem(firstEnum, indent, false);
                if (firstEnum)
                {
                    firstEnum = false;
                }

                Callback?.Process(item, item?.GetType() ?? instanceType.GetGenericArguments()[0], builder, indent + 4, currentDepth + 1);
            }

            builder.EndEnumerable(indent, instance.GetType());

            return(true);
        }

        return(false);
    }
    public int Order => 1; //make sure this part takes over everything :)

    public bool Process(object?instance, Type instanceType, IObjectDumperResultBuilder builder, int indent, int currentDepth)
    {
        if (instanceType.IsValueType)
        {
            return(false);
        }
        throw new InvalidOperationException();
    }
예제 #6
0
    public bool Process(object?instance, Type instanceType, IObjectDumperResultBuilder builder, int indent, int currentDepth)
    {
        if (instance is DateTime dt)
        {
            builder.AddSingleValue(dt.ToString("yyyy-MM-dd HH:mm:ss"), instance.GetType());

            return(true);
        }

        return(false);
    }
예제 #7
0
    public bool Process(object?instance, Type instanceType, IObjectDumperResultBuilder builder, int indent, int currentDepth)
    {
        if (instance == null)
        {
            builder.AddSingleValue(instance, instanceType);

            return(true);
        }

        return(false);
    }
예제 #8
0
    public bool Process(object?instance, Type instanceType, IObjectDumperResultBuilder builder, int indent, int currentDepth)
    {
        if (instance is string)
        {
            builder.AddSingleValue(instance.ToString(), instance.GetType());

            return(true);
        }

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

        var type = instance.GetType();

        if (type.IsPrimitive || type.IsEnum)
        {
            builder.AddSingleValue(instance, instance.GetType());

            return(true);
        }

        return(false);
    }
예제 #10
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);
    }
예제 #11
0
 public object?Transform(object?instance, IObjectDumperResultBuilder builder, int indent, int currentDepth) => instance;
예제 #12
0
 public bool ShouldProcess(object?instance, IObjectDumperResultBuilder builder, int indent, int currentDepth) => true;
예제 #13
0
    public static string Dump<T>(this T instance, IObjectDumperResultBuilder builder, IEnumerable<IObjectDumperPart> customTypeHandlers)
    {
        ComposableObjectDumperFactory.Create(customTypeHandlers).Process(instance, typeof(T), builder, 4, 1);

        return builder.ToString();
    }
예제 #14
0
 public static string Dump<T>(this T instance, IObjectDumperResultBuilder builder, params IObjectDumperPart[] customTypeHandlers)
     => Dump(instance, builder, (IEnumerable<IObjectDumperPart>)customTypeHandlers);
예제 #15
0
 public bool Process(object?instance, Type instanceType, IObjectDumperResultBuilder builder, int indent, int currentDepth)
 => false;