protected override ProjectElement CreateChildElement(string name) { var item = RootElement.CreateItemElement(name); AppendChild(item); return(item); }
/// <summary> /// Adds an item to the current item group. /// </summary> /// <param name="itemGroup">The parent item group to add the item to.</param> /// <param name="itemType">The type of the item to add.</param> /// <param name="include">The file or wildcard to include in the list of items.</param> /// <param name="exclude">An optional file or wildcard to exclude from the list of items.</param> /// <param name="metadata">An optional <see cref="IDictionary{String,String}"/> containing metadata for the item.</param> /// <param name="remove">The file or wildcard to remove from the list of items.</param> /// <param name="update">The file or wildcard to update in the list of items.</param> /// <param name="condition">An optional condition to add to the item.</param> /// <param name="keepDuplicates">Specifies whether an item should be added to the target group if it's an exact duplicate of an existing item.</param> /// <param name="keepMetadata">The metadata for the source items to add to the target items.</param> /// <param name="label">An optional label to add to the item.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> private ProjectCreator Item( ProjectItemGroupElement itemGroup, string itemType, string include, string exclude = null, IDictionary <string, string> metadata = null, string remove = null, string update = null, string condition = null, string keepDuplicates = null, string keepMetadata = null, string label = null) { ProjectItemElement item = include == null ? RootElement.CreateItemElement(itemType) : RootElement.CreateItemElement(itemType, include); item.Remove = remove; item.Update = update; // Item must be added after Include, Update, or Remove is set but before metadata is added itemGroup.AppendChild(item); if (metadata != null) { foreach (KeyValuePair <string, string> metadatum in metadata.Where(i => i.Value != null)) { item.AddMetadata(metadatum.Key, metadatum.Value); } } item.Condition = condition; item.Label = label; item.Exclude = exclude; if (keepDuplicates != null) { item.KeepDuplicates = keepDuplicates; } if (keepMetadata != null) { item.KeepMetadata = keepMetadata; } return(this); }
public ProjectItemElement AddItem(string itemType, string include, IEnumerable <KeyValuePair <string, string> > metadata) { var item = RootElement.CreateItemElement(itemType, include); if (metadata != null) { foreach (var data in metadata) { item.AddMetadata(data.Key, data.Value); } } var lastChild = LastChild; foreach (var existingItem in Items) { var compare = string.Compare(item.ItemType, existingItem.ItemType, StringComparison.OrdinalIgnoreCase); if (compare == 0) { if (string.Compare(item.Include, existingItem.Include, StringComparison.OrdinalIgnoreCase) >= 0) { continue; } lastChild = existingItem.PreviousSibling; break; } if (compare < 0) { lastChild = existingItem.PreviousSibling; break; } } InsertAfterChild(item, lastChild); return(item); }