Web-Extension Collection Classes
Web-Extension Collection Classes
This guide shows how the four web-extension collection classes in Aspose.Words FOSS for .NET — TaskPaneCollection, WebExtensionBindingCollection, WebExtensionPropertyCollection, and WebExtensionReferenceCollection — share a single collection contract through the abstract BaseWebExtensionCollection base class. For what task panes, bindings, and web extension properties actually represent, see the Web Extensions guide; this page covers only the container API they all share.
BaseWebExtensionCollection: One Contract, Four Collections
BaseWebExtensionCollection is the base class for TaskPaneCollection, WebExtensionBindingCollection, WebExtensionPropertyCollection, and WebExtensionReferenceCollection. It implements IEnumerable<T> and defines every member these four concrete collections expose — none of the four subclasses declares additional methods or properties of its own beyond what the base class provides.
Adding, Removing, and Counting Items
Add(item) adds the specified item to the collection. Clear() removes all elements. Remove(index) removes the item at the specified index — it takes a positional index, not an item reference, so removing a specific item means first locating its index. Count reports the number of elements currently in the collection.
Enumerating a Collection
GetEnumerator() returns an enumerator that can iterate through the collection, so any BaseWebExtensionCollection-derived collection supports a foreach loop over its items without type-specific iteration code.
Tips and Best Practices
- Because all four collections share the same base contract, code written against
BaseWebExtensionCollection’sAdd,Clear,Remove,Count, andGetEnumeratormembers works uniformly acrossTaskPaneCollection,WebExtensionBindingCollection,WebExtensionPropertyCollection, andWebExtensionReferenceCollection. Remove(index)takes a positional index — if you only have the item itself, enumerate the collection to find its index first, or track the index at insertion time.- Read
Countbefore iterating, orforeachover the collection directly withGetEnumerator()rather than indexing manually, since the base contract does not expose a positional getter. - Call
Clear()when you need to reset a collection rather than repeatedly callingRemovein a loop.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
Remove doesn’t accept the item itself | Remove(index) on BaseWebExtensionCollection-derived collections takes a positional index, not a reference | Find the item’s index first (for example while enumerating), then call Remove(index) |
| Iterating one of the four collections feels duplicated across types | Each collection is a separate concrete type, but they all share BaseWebExtensionCollection’s members | Write shared iteration or utility logic once against the members Add, Clear, Remove, Count, and GetEnumerator common to all four |
| Unsure which concrete collection type a piece of code needs | The four collections are exposed from different properties on WebExtension and Document | Check the Web Extensions guide for which property returns which collection type |
FAQ
Why do the four web-extension collections behave the same way?
They all derive from the same abstract base class, BaseWebExtensionCollection, which defines Add, Clear, Remove, Count, and GetEnumerator — none of the four subclasses adds its own members.
How do I remove a specific item from one of these collections?
Call Remove(index) with the item’s positional index — locate the index by enumerating the collection first if you only have the item reference.
Can I iterate any of these four collections the same way?
Yes — all four implement IEnumerable<T> through BaseWebExtensionCollection, so GetEnumerator() / foreach works identically across them.
Where do I learn what a WebExtensionBinding or TaskPane item actually represents?
See the Web Extensions guide — this page covers only the shared collection container behavior, not the domain objects the collections hold.
API Reference Summary
| Class/Method | Description |
|---|---|
BaseWebExtensionCollection | Abstract base class shared by all four web-extension collection types |
BaseWebExtensionCollection.Add(item) | Adds an item to the collection |
BaseWebExtensionCollection.Clear() | Removes all elements from the collection |
BaseWebExtensionCollection.Remove(index) | Removes the item at the specified index |
BaseWebExtensionCollection.GetEnumerator() | Returns an enumerator for iterating the collection |
BaseWebExtensionCollection.Count | Number of elements in the collection |
TaskPaneCollection | Concrete BaseWebExtensionCollection of TaskPane items |
WebExtensionBindingCollection | Concrete BaseWebExtensionCollection of WebExtensionBinding items |
WebExtensionPropertyCollection | Concrete BaseWebExtensionCollection of WebExtensionProperty items |
WebExtensionReferenceCollection | Concrete BaseWebExtensionCollection of WebExtensionReference items |