private static SyntaxList<AttributeListSyntax> GetAttributes(ISymbol symbol, IFilterVisitor filterVisitor, bool inOneLine = false) { var attrs = symbol.GetAttributes(); if (attrs.Length > 0) { var attrList = (from attr in attrs where !(attr.AttributeClass is IErrorTypeSymbol) where attr?.AttributeConstructor != null where filterVisitor.CanVisitAttribute(attr.AttributeConstructor) select GetAttributeSyntax(attr)).ToList(); if (attrList.Count > 0) { if (inOneLine) { return SyntaxFactory.SingletonList( SyntaxFactory.AttributeList( SyntaxFactory.SeparatedList(attrList))); } return SyntaxFactory.List( from attr in attrList select SyntaxFactory.AttributeList( SyntaxFactory.SingletonSeparatedList(attr))); } } return new SyntaxList<AttributeListSyntax>(); }
private static SyntaxList<AttributeListSyntax> GetAttributes(ISymbol symbol, IFilterVisitor filterVisitor, bool inOneLine = false, bool isExtensionMethod = false) { var attrs = symbol.GetAttributes(); List<AttributeSyntax> attrList = null; if (attrs.Length > 0) { attrList = (from attr in attrs where !(attr.AttributeClass is IErrorTypeSymbol) where attr?.AttributeConstructor != null where filterVisitor.CanVisitAttribute(attr.AttributeConstructor) select GetAttributeSyntax(attr)).ToList(); } if (isExtensionMethod) { attrList = attrList ?? new List<AttributeSyntax>(); attrList.Add( SyntaxFactory.Attribute( SyntaxFactory.ParseName(nameof(System.Runtime.CompilerServices.ExtensionAttribute)))); } if (attrList?.Count > 0) { if (inOneLine) { return SyntaxFactory.SingletonList( SyntaxFactory.AttributeList( SyntaxFactory.SeparatedList(attrList))); } return SyntaxFactory.List( from attr in attrList select SyntaxFactory.AttributeList( SyntaxFactory.SingletonSeparatedList(attr))); } return new SyntaxList<AttributeListSyntax>(); }