public static string GenerateDocumentStorageCode(DocumentMapping[] mappings) { var writer = new SourceWriter(); // TODO -- get rid of the magic strings var namespaces = new List<string> {"System", "Marten", "Marten.Schema", "Marten.Linq", "Marten.Util", "Npgsql", "Remotion.Linq"}; namespaces.AddRange(mappings.Select(x => x.DocumentType.Namespace)); namespaces.Distinct().OrderBy(x => x).Each(x => writer.WriteLine($"using {x};")); writer.BlankLine(); writer.StartNamespace("Marten.GeneratedCode"); mappings.Each(x => { x.GenerateDocumentStorage(writer); writer.BlankLine(); writer.BlankLine(); }); writer.FinishBlock(); var code = writer.Code(); return code; }
public static string GenerateDocumentStorageCode(DocumentMapping[] mappings) { var writer = new SourceWriter(); // TODO -- get rid of the magic strings var namespaces = new List<string> { "System", "Marten", "Marten.Schema", "Marten.Services", "Marten.Linq", "Marten.Util", "Npgsql", "Remotion.Linq", typeof (NpgsqlDbType).Namespace, typeof (IEnumerable<>).Namespace, typeof(DbDataReader).Namespace, typeof(CancellationToken).Namespace, typeof(Task).Namespace }; namespaces.AddRange(mappings.Select(x => x.DocumentType.Namespace)); namespaces.Distinct().OrderBy(x => x).Each(x => writer.WriteLine($"using {x};")); writer.BlankLine(); writer.StartNamespace("Marten.GeneratedCode"); mappings.Each(x => { GenerateDocumentStorage(x, writer); writer.BlankLine(); writer.BlankLine(); }); writer.FinishBlock(); return writer.Code(); }