mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-03 01:25:44 -05:00
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:
@@ -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());
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user