Add generic reference if needed for Sql Input Binding (#1294)

* add generic reference if needed

* only check input binding for now
This commit is contained in:
Lucy Zhang
2021-11-11 10:54:42 -08:00
committed by GitHub
parent a3c69f3dd2
commit 8487703c21
3 changed files with 13 additions and 2 deletions

View File

@@ -23,6 +23,8 @@ namespace Microsoft.SqlTools.ServiceLayer.AzureFunctions
/// </summary>
class AddSqlBindingOperation
{
public const string GenericClass = "System.Collections.Generic";
public AddSqlBindingParams Parameters { get; }
public AddSqlBindingOperation(AddSqlBindingParams parameters)
@@ -71,6 +73,17 @@ namespace Microsoft.SqlTools.ServiceLayer.AzureFunctions
// Replace the node in the tree
root = root.ReplaceNode(azureFunction, updatedMethod);
if (this.Parameters.bindingType == BindingType.input)
{
// Check if file has System.Collections.Generic reference, insert it if not
IEnumerable<UsingDirectiveSyntax> usingDirectives = root.DescendantNodes().OfType<UsingDirectiveSyntax>();
var genericUsingDirective = usingDirectives.Where(usingDirective => usingDirective.Name.ToString() == GenericClass);
if (genericUsingDirective.Count() == 0)
{
root = root.AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(GenericClass)).NormalizeWhitespace().WithTrailingTrivia(SyntaxFactory.ElasticCarriageReturnLineFeed));
}
}
// write updated tree to file
var workspace = new AdhocWorkspace();
var syntaxTree = CSharpSyntaxTree.ParseText(root.ToString());

View File

@@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
namespace Company.Namespace
{

View File

@@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
namespace Company.Namespace
{