/// <summary> /// Clones this instance. /// </summary> /// <returns></returns> public TagItemCollection Clone(bool withMembers) { TagItemCollection tic = new TagItemCollection(Environment, Name); if (withMembers) { tic.AddRange(this); } return(tic); }
/// <summary> /// Gets all items with the specified name /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public TagItemCollection GetAllByName(string name) { TagItemCollection list = new TagItemCollection(Environment); foreach (TagItem item in this) { if (StringComparer.OrdinalIgnoreCase.Equals(name, item.Name)) { list.Add(item); } } return(list); }
internal string GetItemValue(string item, string Key, string separator) { TagItemCollection items = GetItems(item ?? DefaultItem); if (items == null || items.Count == 0) { return(null); } if (items.Count == 1) { return(items[0].ExpandedValue(Context, Key)); } if (separator == null) { throw new InvalidOperationException(); } StringBuilder sb = new StringBuilder(); bool first = true; foreach (TagItem i in items) { if (first) { first = false; } else { sb.Append(separator); } sb.Append(i.ExpandedValue(Context, Key)); } return(sb.ToString()); }
/// <summary> /// Creates a batch instance over a single item /// </summary> /// <typeparam name="TKey">The type of the key.</typeparam> /// <param name="definition">The definition.</param> /// <param name="checkConditions">if set to <c>true</c> [check conditions].</param> /// <returns></returns> private IEnumerable <TagBatchInstance <TKey> > RunBatchInternal <TKey>(TagBatchDefinition <TKey> definition, bool checkConditions) where TKey : class { AutoKeyedCollection <string, TagItemCollection> restLists = new AutoKeyedCollection <string, TagItemCollection>(StringComparer.OrdinalIgnoreCase); AutoKeyedCollection <string, TagItemCollection> currentLists = new AutoKeyedCollection <string, TagItemCollection>(StringComparer.OrdinalIgnoreCase); int nLeft = 0; foreach (string itemName in definition.ItemsUsed) { TagItemCollection tt = Items.GetAllByName(itemName); restLists.Add(tt); currentLists.Add(tt.Clone(false)); nLeft += tt.Count; } // Create a list of valid items IList <Pair <string, string> > constraints = definition.Constraints; TagBatchInstance <TKey> instance = new TagBatchInstance <TKey>(this, definition); do { string[] constraintValues = new string[constraints.Count]; for (int iList = 0; iList < restLists.Count; iList++) { TagItemCollection rest = restLists[iList]; TagItemCollection current = currentLists[iList]; string listName = restLists[iList].Name; for (int iItem = 0; iItem < rest.Count; iItem++) { TagItem ti = rest[iItem]; int n = 0; bool next = false; foreach (Pair <string, string> p in constraints) { if (!string.IsNullOrEmpty(p.First) && !StringComparer.OrdinalIgnoreCase.Equals(p.First, listName)) { continue; } string v = ti.ExpandedKey(p.Second); if ((object)constraintValues[n] == null) { constraintValues[n++] = v; } else if (!StringComparer.OrdinalIgnoreCase.Equals(v, constraintValues[n++])) { next = true; break; } } if (next) { continue; } else { rest.RemoveAt(iItem--); current.Add(ti); nLeft--; } } } // At least one item was added to current instance.Fill(currentLists, constraintValues); if (!checkConditions || instance.ConditionResult()) { yield return(instance); } foreach (TagItemCollection current in currentLists) { current.Clear(); } }while (nLeft > 0); }
/// <summary> /// Initializes a new instance of the <see cref="TagEnvironment"/> class. /// </summary> public TagEnvironment() { _properties = new TagPropertyCollection(this); _items = new TagItemCollection(this); }