Ejemplo n.º 1
0
                private void WritePrinter(IPrint print)
                {
                    var type = print.GetType();
                    var childObjectWalker = new ObjectWalker(
                        this.Indent, this.Level + 2, this.Builder);

                    bool unAttr = type.GetTypeInfo().GetCustomAttribute <PrintAttribute>() == null;

                    this.WriteIndent();
                    this.Builder.Append("{");

                    foreach (var f in type.GetRuntimeFields().Where(f =>
                                                                    !f.IsStatic &&
                                                                    (unAttr || f.GetCustomAttribute <PrintAttribute>() != null) &&
                                                                    f.Name[0] != '<'))
                    {
                        var fieldWalker = new FieldWalker(f, childObjectWalker,
                                                          this.Indent, this.Level + 1, this.Builder);
                        fieldWalker.Walk(print);
                    }

                    foreach (var p in type.GetRuntimeProperties())
                    {
                        if (p.CanRead && (unAttr || p.GetCustomAttribute <PrintAttribute>() != null))
                        {
                            var propertyWalker = new PropertyWalker(p, childObjectWalker,
                                                                    this.Indent, this.Level + 1, this.Builder);
                            propertyWalker.Walk(print);
                        }
                    }

                    this.WriteIndent();
                    this.Builder.Append("}");
                }