microsoft/healthcare-shared-components

Public

mirrored from https://github.com/microsoft/healthcare-shared-componentsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.0.0-1.0.79

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

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
6using System;
7using Microsoft.CodeAnalysis.CSharp;
8using Microsoft.CodeAnalysis.CSharp.Syntax;
9using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
10
11namespace 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}