/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> /// <returns> /// A new object that is a copy of this instance. /// </returns> public virtual object Clone() { CodeElement clone = DoClone(); // Copy base state clone._name = _name; lock (_childrenLock) { for (int childIndex = 0; childIndex < BaseChildren.Count; childIndex++) { ICodeElement child = BaseChildren[childIndex]; ICodeElement childClone = child.Clone() as ICodeElement; childClone.Parent = clone; } } foreach (string key in _extendedProperties.Keys) { clone[key] = _extendedProperties[key]; } return(clone); }
/// <summary> /// Writes the end block for an element. /// </summary> /// <param name="codeElement">The code element.</param> private void WriteEndBlock(CodeElement codeElement) { TabCount--; MemberElement memberElement = codeElement as MemberElement; string blockName = string.Empty; if (memberElement != null) { if (memberElement.ElementType == ElementType.Method || memberElement.ElementType == ElementType.Constructor) { MethodElement methodElement = memberElement as MethodElement; if (methodElement != null && methodElement.IsOperator) { blockName = VBKeyword.Operator; } else if (memberElement.Type != null) { blockName = VBKeyword.Function; } else { blockName = VBKeyword.Sub; } } } if (string.IsNullOrEmpty(blockName)) { TypeElement typeElement = codeElement as TypeElement; if (typeElement != null) { blockName = EnumUtilities.ToString(typeElement.Type); } if (string.IsNullOrEmpty(blockName)) { blockName = EnumUtilities.ToString(codeElement.ElementType); } } WriteIndented(VBKeyword.End + ' ' + blockName); }
/// <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(); } } } }