/// <summary> /// Arranges the code elements according to the configuration supplied /// in the constructor. /// </summary> /// <param name="originalElements">Original elements</param> /// <returns>An arranged collection of code elements.</returns> public ReadOnlyCollection <ICodeElement> Arrange(ReadOnlyCollection <ICodeElement> originalElements) { GroupElement rootElement = new GroupElement(); if (originalElements != null) { List <ICodeElement> elements = new List <ICodeElement>(); NamespaceElement firstNamespace = null; for (int elementIndex = 0; elementIndex < originalElements.Count; elementIndex++) { ICodeElement element = originalElements[elementIndex]; ICodeElement elementClone = element.Clone() as ICodeElement; elements.Add(elementClone); if (firstNamespace == null) { Action <ICodeElement> findFirstNamespace = delegate(ICodeElement processElement) { if (firstNamespace == null) { NamespaceElement namespaceElement = processElement as NamespaceElement; if (namespaceElement != null) { firstNamespace = namespaceElement; } } }; ElementUtilities.ProcessElementTree(elementClone, findFirstNamespace); } } MoveUsings(elements, firstNamespace); foreach (ICodeElement element in elements) { ArrangerChain.ArrangeElement(rootElement, element); } } List <ICodeElement> arranged = new List <ICodeElement>(rootElement.Children); foreach (ICodeElement arrangedElement in arranged) { // Remove the root element as the parent. arrangedElement.Parent = null; } return(arranged.AsReadOnly()); }
/// <summary> /// Determines whether or not the specified element can be arranged by /// this arranger. /// </summary> /// <param name="parentElement">The parent element.</param> /// <param name="codeElement">The code element.</param> /// <returns> /// <c>true</c> if this instance can arrange the specified parent element; otherwise, <c>false</c>. /// </returns> public virtual bool CanArrange(ICodeElement parentElement, ICodeElement codeElement) { // Clone the instance and assign the parent ICodeElement testCodeElement = codeElement; if (_filter == null && _elementConfiguration.FilterBy != null) { _filter = CreateElementFilter(_elementConfiguration.FilterBy); } if (parentElement != null && _filter != null && _filter.RequiredScope == ElementAttributeScope.Parent) { testCodeElement = codeElement.Clone() as ICodeElement; testCodeElement.Parent = parentElement.Clone() as ICodeElement; } return((_elementConfiguration.ElementType == ElementType.NotSpecified || codeElement.ElementType == _elementConfiguration.ElementType) && (_filter == null || _filter.IsMatch(testCodeElement))); }
/// <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> /// Determines whether or not the specified element can be arranged by /// this arranger. /// </summary> /// <param name="parentElement">The parent element.</param> /// <param name="codeElement">The code element.</param> /// <returns> /// <c>true</c> if this instance can arrange the specified parent element; otherwise, <c>false</c>. /// </returns> public virtual bool CanArrange(ICodeElement parentElement, ICodeElement codeElement) { // Clone the instance and assign the parent ICodeElement testCodeElement = codeElement; if (_filter == null && _elementConfiguration.FilterBy != null) { _filter = CreateElementFilter(_elementConfiguration.FilterBy); } if (parentElement != null && _filter != null && _filter.RequiredScope == ElementAttributeScope.Parent) { testCodeElement = codeElement.Clone() as ICodeElement; testCodeElement.Parent = parentElement.Clone() as ICodeElement; } return (_elementConfiguration.ElementType == ElementType.NotSpecified || codeElement.ElementType == _elementConfiguration.ElementType) && (_filter == null || _filter.IsMatch(testCodeElement)); }