Add error for sql bindings when .net 5 (#1259)

* add error for sql bindings when .net 5

* add test

* cleanup linq stuff and move out common code
This commit is contained in:
Kim Santiago
2021-10-07 16:13:53 -07:00
committed by GitHub
parent f2da10f23a
commit 0f0df25119
10 changed files with 121 additions and 19 deletions

View File

@@ -21,8 +21,6 @@ namespace Microsoft.SqlTools.ServiceLayer.AzureFunctions
/// </summary>
class GetAzureFunctionsOperation
{
const string functionAttributeText = "FunctionName";
public GetAzureFunctionsParams Parameters { get; }
public GetAzureFunctionsOperation(GetAzureFunctionsParams parameters)
@@ -44,15 +42,11 @@ namespace Microsoft.SqlTools.ServiceLayer.AzureFunctions
SyntaxTree tree = CSharpSyntaxTree.ParseText(text);
CompilationUnitSyntax root = tree.GetCompilationUnitRoot();
// Look for Azure Functions in the file
// Get all method declarations
IEnumerable<MethodDeclarationSyntax> methodDeclarations = root.DescendantNodes().OfType<MethodDeclarationSyntax>();
// get all the method declarations with the FunctionName attribute
IEnumerable<MethodDeclarationSyntax> methodsWithFunctionAttributes = methodDeclarations.Where(md => md.AttributeLists.Count > 0).Where(md => md.AttributeLists.Where(a => a.Attributes.Where(attr => attr.Name.ToString().Contains(functionAttributeText)).Count() == 1).Count() == 1);
IEnumerable<MethodDeclarationSyntax> methodsWithFunctionAttributes = AzureFunctionsUtils.GetMethodsWithFunctionAttributes(root);
// Get FunctionName attributes
IEnumerable<AttributeSyntax> functionNameAttributes = methodsWithFunctionAttributes.Select(md => md.AttributeLists.Select(a => a.Attributes.Where(attr => attr.Name.ToString().Contains(functionAttributeText)).First()).First());
IEnumerable<AttributeSyntax> functionNameAttributes = methodsWithFunctionAttributes.Select(md => md.AttributeLists.Select(a => a.Attributes.Where(attr => attr.Name.ToString().Equals(AzureFunctionsUtils.functionAttributeText)).First()).First());
// Get the function names in the FunctionName attributes
IEnumerable<AttributeArgumentSyntax> nameArgs = functionNameAttributes.Select(a => a.ArgumentList.Arguments.First());