Exemple #1
0
        private static void GenerateDeserializer(IReadOnlyList <NodeModel> models, StringBuilder stringBuilder)
        {
            CodeBuilder builder = new CodeBuilder(stringBuilder, 4);

            foreach (var nodeModel in models)
            {
                builder.AppendStart(0, $"case \"{TypeTag(nodeModel.TypeName)}\": return ");
                if (nodeModel.IsSingleton)
                {
                    builder.AppendLine($"{nodeModel.TypeName}.Instance;");
                    continue;
                }
                builder.Append($"new {nodeModel.TypeName}(");
                for (var index = 0; index < nodeModel.SubNodes.Count; index++)
                {
                    var supNode = nodeModel.SubNodes[index];
                    if (index != 0)
                    {
                        builder.Append(", ");
                    }
                    builder.Append($"{supNode.ConstructorArgumentName}: Get{(supNode.IsNullable ? "Nullable" : null)}SubNode{(supNode.IsList ? "List" : null)}<TNode, {supNode.PropertyType}>(rootElement, reader, \"{supNode.PropertyName}\")");
                }

                for (var index = 0; index < nodeModel.Properties.Count; index++)
                {
                    var modelProperty = nodeModel.Properties[index];
                    if (index != 0 || nodeModel.SubNodes.Count > 0)
                    {
                        builder.Append(", ");
                    }
                    builder.Append($"{modelProperty.ConstructorArgumentName}: Read{GetPropertyTypeName(modelProperty: modelProperty)}(rootElement, reader, \"{modelProperty.PropertyName}\")");
                }

                builder.AppendLine(");");
            }