/// <summary> /// Applies attributes and comments to a code element. /// </summary> /// <param name="codeElement">Code element to apply to.</param> /// <param name="comments">Comments to apply.</param> /// <param name="attributes">Attributes to apply.</param> protected static void ApplyCommentsAndAttributes( CodeElement codeElement, ReadOnlyCollection <ICommentElement> comments, ReadOnlyCollection <AttributeElement> attributes) { CommentedElement commentedElement = codeElement as CommentedElement; if (commentedElement != null) { // // Add any header comments // foreach (ICommentElement comment in comments) { commentedElement.AddHeaderComment(comment); } } AttributedElement attributedElement = codeElement as AttributedElement; if (attributedElement != null) { foreach (AttributeElement attribute in attributes) { attributedElement.AddAttribute(attribute); // // Treat attribute comments as header comments // if (attribute.HeaderComments.Count > 0) { foreach (ICommentElement comment in attribute.HeaderComments) { attributedElement.AddHeaderComment(comment); } attribute.ClearHeaderCommentLines(); } } } }
/// <summary> /// Writes each element using the specified visitor. /// </summary> /// <param name="codeElements">The code elements.</param> /// <param name="writer">The writer.</param> /// <param name="visitor">The visitor.</param> public static void WriteVisitElements( ReadOnlyCollection <ICodeElement> codeElements, TextWriter writer, ICodeElementVisitor visitor) { for (int index = 0; index < codeElements.Count; index++) { ICodeElement codeElement = codeElements[index]; if (codeElement != null) { CommentedElement commentedElement = codeElement as CommentedElement; if (index > 0 && ((commentedElement != null && commentedElement.HeaderComments.Count > 0) || codeElement is NamespaceElement || codeElement is TypeElement || codeElement is RegionElement || codeElement is ConditionDirectiveElement || (codeElement is MemberElement && !(codeElement is FieldElement)) || (!(codeElement is GroupElement) && codeElement.ElementType != codeElements[index - 1].ElementType) || codeElements[index - 1] is GroupElement)) { writer.WriteLine(); } codeElement.Accept(visitor); if (codeElements.Count > 1 && index < codeElements.Count - 1) { writer.WriteLine(); if ((codeElement is RegionElement || codeElement is ConditionDirectiveElement) && codeElement.Parent == null && !(codeElements.Count > index + 1 && codeElements[index + 1] is NamespaceElement)) { writer.WriteLine(); } } } } }