/// <summary> /// Creates an element inserter. /// </summary> /// <param name="elementType">Type of the element.</param> /// <param name="sortBy">The sort by.</param> /// <param name="groupBy">The group by.</param> /// <param name="parentConfiguration">The parent configuration.</param> /// <returns>An appropriate inserter.</returns> private static IElementInserter CreateElementInserter( ElementType elementType, SortBy sortBy, GroupBy groupBy, ConfigurationElement parentConfiguration) { IElementInserter inserter = null; if (sortBy != null) { inserter = new SortedInserter(elementType, sortBy); } if (groupBy != null && groupBy.InnerGroupBy != null) { inserter = new GroupedInserter(groupBy.InnerGroupBy, inserter); } if (groupBy != null) { inserter = new GroupedInserter(groupBy, inserter); } if (inserter == null) { inserter = new DefaultElementInserter(); } return(inserter); }
/// <summary> /// Creates a new GroupedInserter using the specified grouping configuration /// and sorter. /// </summary> /// <param name="groupBy">The group by.</param> /// <param name="innerInserter">The inner inserter.</param> public GroupedInserter(GroupBy groupBy, IElementInserter innerInserter) { if (groupBy == null) { throw new ArgumentNullException("groupBy"); } _groupBy = groupBy.Clone() as GroupBy; _innerInserter = innerInserter; if (!string.IsNullOrEmpty(groupBy.AttributeCapture)) { _captureRegex = new Regex(_groupBy.AttributeCapture); } }
/// <summary> /// Arranges the element in within the code tree represented in the specified /// builder. /// </summary> /// <param name="parentElement">The parent element.</param> /// <param name="codeElement">The code element.</param> public virtual void ArrangeElement(ICodeElement parentElement, ICodeElement codeElement) { if (codeElement.Children.Count > 0) { if (_childrenArranger == null) { _childrenArranger = ElementArrangerFactory.CreateChildrenArranger(_elementConfiguration); } if (_childrenArranger != null) { List<ICodeElement> children = new List<ICodeElement>(codeElement.Children); codeElement.ClearChildren(); foreach (ICodeElement childElement in children) { ArrangeChildElement(codeElement, childElement); } // // For condition directives, arrange the children of each node in the list. // ConditionDirectiveElement conditionDirective = codeElement as ConditionDirectiveElement; if (conditionDirective != null) { // // Skip the first instance since we've already arranged those child elements. // conditionDirective = conditionDirective.ElseCondition; } while (conditionDirective != null) { children = new List<ICodeElement>(conditionDirective.Children); conditionDirective.ClearChildren(); foreach (ICodeElement childElement in children) { ArrangeChildElement(conditionDirective, childElement); } conditionDirective = conditionDirective.ElseCondition; } } } if (_inserter == null) { _inserter = CreateElementInserter( _elementConfiguration.ElementType, _elementConfiguration.SortBy, _elementConfiguration.GroupBy, _parentConfiguration); } // For Type elements, if interdependent static fields are present, correct their // ordering. TypeElement typeElement = codeElement as TypeElement; if (typeElement != null && (typeElement.Type == TypeElementType.Class || typeElement.Type == TypeElementType.Structure || typeElement.Type == TypeElementType.Module)) { CorrectStaticFieldDependencies(typeElement); } _inserter.InsertElement(parentElement, codeElement); }
/// <summary> /// Arranges the element in within the code tree represented in the specified /// builder. /// </summary> /// <param name="parentElement">The parent element.</param> /// <param name="codeElement">The code element.</param> public virtual void ArrangeElement(ICodeElement parentElement, ICodeElement codeElement) { if (codeElement.Children.Count > 0) { if (_childrenArranger == null) { _childrenArranger = ElementArrangerFactory.CreateChildrenArranger(_elementConfiguration); } if (_childrenArranger != null) { List <ICodeElement> children = new List <ICodeElement>(codeElement.Children); codeElement.ClearChildren(); foreach (ICodeElement childElement in children) { ArrangeChildElement(codeElement, childElement); } // // For condition directives, arrange the children of each node in the list. // ConditionDirectiveElement conditionDirective = codeElement as ConditionDirectiveElement; if (conditionDirective != null) { // // Skip the first instance since we've already arranged those child elements. // conditionDirective = conditionDirective.ElseCondition; } while (conditionDirective != null) { children = new List <ICodeElement>(conditionDirective.Children); conditionDirective.ClearChildren(); foreach (ICodeElement childElement in children) { ArrangeChildElement(conditionDirective, childElement); } conditionDirective = conditionDirective.ElseCondition; } } } if (_inserter == null) { _inserter = CreateElementInserter( _elementConfiguration.ElementType, _elementConfiguration.SortBy, _elementConfiguration.GroupBy, _parentConfiguration); } // For Type elements, if interdependent static fields are present, correct their // ordering. TypeElement typeElement = codeElement as TypeElement; if (typeElement != null && (typeElement.Type == TypeElementType.Class || typeElement.Type == TypeElementType.Structure || typeElement.Type == TypeElementType.Module)) { CorrectStaticFieldDependencies(typeElement); } _inserter.InsertElement(parentElement, codeElement); }