microsoft/healthcare-shared-components
Publicmirrored from https://github.com/microsoft/healthcare-shared-componentsAvailable
tools/Microsoft.Health.Extensions.BuildTimeCodeGenerator/Sql/MutableSqlModelGenerator.cs
38lines · modecode
| 1 | // ------------------------------------------------------------------------------------------------- |
| 2 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. |
| 4 | // ------------------------------------------------------------------------------------------------- |
| 5 | |
| 6 | using System; |
| 7 | using Microsoft.CodeAnalysis.CSharp; |
| 8 | using Microsoft.CodeAnalysis.CSharp.Syntax; |
| 9 | using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; |
| 10 | |
| 11 | namespace Microsoft.Health.Extensions.BuildTimeCodeGenerator.Sql |
| 12 | { |
| 13 | /// <summary> |
| 14 | /// Generates a class with members based on CREATE TABLE and CREATE PROCEDURE statements in a .sql file. |
| 15 | /// </summary> |
| 16 | public class MutableSqlModelGenerator : SqlModelGenerator |
| 17 | { |
| 18 | public MutableSqlModelGenerator(string[] args) |
| 19 | : base(args) |
| 20 | { |
| 21 | if (args.Length != 1) |
| 22 | { |
| 23 | throw new InvalidOperationException($"Only one file is supported as an argument for {nameof(MutableSqlModelGenerator)}"); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | protected override SqlVisitor[] Visitors => new SqlVisitor[] { new CreateTableVisitor(), new CreateProcedureVisitor() }; |
| 28 | |
| 29 | protected override MemberDeclarationSyntax[] WrapMembers(MemberDeclarationSyntax[] members, string containingTypeName) |
| 30 | { |
| 31 | MemberDeclarationSyntax classDeclarationSyntax = ClassDeclaration(containingTypeName) |
| 32 | .WithModifiers(TokenList(Token(SyntaxKind.InternalKeyword))) |
| 33 | .AddMembers(members); |
| 34 | |
| 35 | return new[] { classDeclarationSyntax }; |
| 36 | } |
| 37 | } |
| 38 | } |