mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -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>
|
/// </summary>
|
||||||
class AddSqlBindingOperation
|
class AddSqlBindingOperation
|
||||||
{
|
{
|
||||||
|
public const string GenericClass = "System.Collections.Generic";
|
||||||
|
|
||||||
public AddSqlBindingParams Parameters { get; }
|
public AddSqlBindingParams Parameters { get; }
|
||||||
|
|
||||||
public AddSqlBindingOperation(AddSqlBindingParams parameters)
|
public AddSqlBindingOperation(AddSqlBindingParams parameters)
|
||||||
@@ -71,6 +73,17 @@ namespace Microsoft.SqlTools.ServiceLayer.AzureFunctions
|
|||||||
// Replace the node in the tree
|
// Replace the node in the tree
|
||||||
root = root.ReplaceNode(azureFunction, updatedMethod);
|
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
|
// write updated tree to file
|
||||||
var workspace = new AdhocWorkspace();
|
var workspace = new AdhocWorkspace();
|
||||||
var syntaxTree = CSharpSyntaxTree.ParseText(root.ToString());
|
var syntaxTree = CSharpSyntaxTree.ParseText(root.ToString());
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.Azure.WebJobs;
|
using Microsoft.Azure.WebJobs;
|
||||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Company.Namespace
|
namespace Company.Namespace
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.Azure.WebJobs;
|
using Microsoft.Azure.WebJobs;
|
||||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Company.Namespace
|
namespace Company.Namespace
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user