protected IEnumerable<CodeAction> GetActions(Document document, SyntaxNode root, MethodDeclarationSyntax node) { var nullableType = node.ChildNodes().OfType<NullableTypeSyntax>().FirstOrDefault(); var objectType = node.ChildNodes().OfType<IdentifierNameSyntax>().FirstOrDefault(); return GetActions(document, root, node, nullableType, objectType); }
private static IList<Tuple<AttributeSyntax, IMethodSymbol>> GetAttributes(MethodDeclarationSyntax currentMethod, SemanticModel semanticModel, string attributeFullName) { var attributeName = attributeFullName.Split('.').Last(); var attributeNameWithoutAttributeSuffix = attributeName.Substring(0, attributeName.Length - "Attribute".Length); var possibleAttributesInSyntax = currentMethod.ChildNodes() .Where(chn => chn is AttributeListSyntax) .Cast<AttributeListSyntax>() .Where(chn => chn.ChildNodes().Any(chchn => chchn is AttributeSyntax)) .Select(chn => (AttributeSyntax) chn.ChildNodes().First(chchn => chchn is AttributeSyntax)) .Where(chchn => chchn.Name.ToString().EndsWith(attributeNameWithoutAttributeSuffix) || chchn.Name.ToString().EndsWith(attributeName)); return possibleAttributesInSyntax .Select(a => Tuple.Create(a, semanticModel.GetSymbolInfo(a).Symbol as IMethodSymbol)) .Where(s => s.Item2.ToString().StartsWith(attributeFullName)) .ToList(); }