/// <summary> /// Adds the give base construct as a child of this code root. /// </summary> /// <param name="child">The chidl object to add.</param> public void AddChild(IBaseConstruct child) { if (child == null) { throw new ArgumentNullException("child"); } if (child is Namespace) { Namespaces.Add(child as Namespace); } else if (child is Struct) { Structs.Add(child as Struct); } else if (child is Interface) { Interfaces.Add(child as Interface); } else if (child is Enumeration) { Enums.Add(child as Enumeration); } else if (child is Delegate) { Delegates.Add(child as Delegate); } else if (child is UsingStatement) { UsingStatements.Add(child as UsingStatement); _usingStatementsAreSorted = false; } else if (child is AttributeSection) { Attributes.Add(child as AttributeSection); } else if (child is Class) { Classes.Add(child as Class); } else { throw new InvalidOperationException("Could not add child of type " + child.GetType()); } if (child is BaseConstruct) { ((BaseConstruct)child).Controller = controller; } }
public ReadOnlyCollection <IBaseConstruct> GetSiblingsOfSameType(Version versionToGet) { List <IBaseConstruct> siblings = new List <IBaseConstruct>(); foreach (CodeRootMapNode child in ParentNode.ChildNodes) { if (child == this) { continue; } IBaseConstruct potentialMatch = child.baseConstructs.GetObject(versionToGet); if (potentialMatch != null && potentialMatch.GetType().Equals(GetFirstValidBaseConstruct().GetType())) { siblings.Add(potentialMatch); } } return(siblings.AsReadOnly()); }
/// <summary> /// This method should be called on a merged object. It merged the minor features of a base construct, like modifiers in a /// C# BC, or parameter names. /// </summary> /// <param name="user">The User's version of the object.</param> /// <param name="newgen">The Template's version of the object.</param> /// <param name="prevgen">The previously generated version of the object.</param> /// <returns>True if the merge was successful. If it returns false, the user will have to manually merge it. </returns> public bool CustomMergeStep(IBaseConstruct user, IBaseConstruct newgen, IBaseConstruct prevgen) { Type thisType = GetType(); if (thisType.IsInstanceOfType(user) == false || thisType.IsInstanceOfType(newgen) == false || thisType.IsInstanceOfType(prevgen) == false) { throw new ArgumentException( string.Format("Cannot merge IBaseConstructs of a different type" + " into this C# BaseConstruct (User = {0}, NewGen = {1}, PrevGen = {2}, This = {3}", user.GetType(), newgen.GetType(), prevgen.GetType(), thisType)); } BaseConstruct userBC = (BaseConstruct)user, newgenBC = (BaseConstruct)newgen, prevgenBC = (BaseConstruct)prevgen; // Comments if (!MergeComments(userBC, newgenBC, prevgenBC)) { return(false); } // Xml Comments if (!Utility.MergeStringCollections(XmlComments, userBC.XmlComments, newgenBC.XmlComments, prevgenBC.XmlComments)) { return(false); } // Name if (!Utility.MergeSingleItem(ref _name, userBC.Name, newgenBC.Name, prevgenBC.Name)) { return(false); } // Attributes if (!MergeAttributes(userBC, newgenBC, prevgenBC)) { return(false); } return(CustomMergeStepInternal(userBC, newgenBC, prevgenBC)); }