protected void AppendWritePart(WritePartNode node, TextBuilder builder) { if (node.FirstChild is ArrayTypeNode) { VisitWriteArray(VARIABLE, STREAM, node.FirstChild as ArrayTypeNode, builder); } else if (node.FirstChild is ListTypeNode) { VisitWriteList(VARIABLE, STREAM, node.FirstChild as ListTypeNode, builder); } else if (node.FirstChild is DictionaryTypeNode) { VisitWriteDictionary(VARIABLE, STREAM, node.FirstChild as DictionaryTypeNode, builder); } else if (node.FirstChild is HashSetTypeNode) { VisitWriteHashSet(VARIABLE, STREAM, node.FirstChild as HashSetTypeNode, builder); } else if (node.FirstChild is PolyClassTypeNode) { VisitWritePolyClass(VARIABLE, STREAM, node.FirstChild as PolyClassTypeNode, builder); } else if (node.FirstChild is TwoDimArrayTypeNode) { VisitWriteTwoDimArray(VARIABLE, STREAM, node.FirstChild as TwoDimArrayTypeNode, builder); } else if (node.FirstChild is StringTypeNode) { VisitWriteString(VARIABLE, STREAM, builder); } else { foreach (var child in node.Children) { if (child is FieldNode) { var field = child as FieldNode; builder.Push(); VisitField(VARIABLE, field, builder); var variable = builder.Pop(); VisitWriteField(variable, STREAM, field.Serialize, builder); } } } }
protected virtual void AppendReadAllFields(ReadPartNode node, TextBuilder builder) { if (node.CreateNew) { builder.WriteLine("if(d == null) d = new {0}();", node.TypeName); } foreach (var child in node.Children) { if (child is FieldNode) { var field = child as FieldNode; builder.Push(); VisitField("d", field, builder); var variable = builder.Pop(); VisitReadField(variable, "o", field.ReadOnly, field.Serialize, builder); } } }