public static AttributeSyntax GetAttribute(this SyntaxNode node, INamedTypeSymbol name) { AttributeSyntax attr = null; if (node is BaseMethodDeclarationSyntax || node is BaseTypeDeclarationSyntax || node is BaseFieldDeclarationSyntax) { var list = (node is BaseMethodDeclarationSyntax ? node.As <BaseMethodDeclarationSyntax>().AttributeLists : node is BaseTypeDeclarationSyntax ? node.As <BaseTypeDeclarationSyntax>().AttributeLists : node.As <BaseFieldDeclarationSyntax>().AttributeLists).ToList(); if (list.Count > 0) { attr = list.SelectMany(o => o.Attributes) .SingleOrDefault(o => TypeProcessor.TryGetTypeSymbol(o) == name); if (attr != null) { return(attr); } } } return(null); }