Web-Extension Collection Classes

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’s Add, Clear, Remove, Count, and GetEnumerator members works uniformly across TaskPaneCollection, WebExtensionBindingCollection, WebExtensionPropertyCollection, and WebExtensionReferenceCollection.
  • 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 Count before iterating, or foreach over the collection directly with GetEnumerator() 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 calling Remove in a loop.

Common Issues

IssueCauseFix
Remove doesn’t accept the item itselfRemove(index) on BaseWebExtensionCollection-derived collections takes a positional index, not a referenceFind the item’s index first (for example while enumerating), then call Remove(index)
Iterating one of the four collections feels duplicated across typesEach collection is a separate concrete type, but they all share BaseWebExtensionCollection’s membersWrite 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 needsThe four collections are exposed from different properties on WebExtension and DocumentCheck 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/MethodDescription
BaseWebExtensionCollectionAbstract 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.CountNumber of elements in the collection
TaskPaneCollectionConcrete BaseWebExtensionCollection of TaskPane items
WebExtensionBindingCollectionConcrete BaseWebExtensionCollection of WebExtensionBinding items
WebExtensionPropertyCollectionConcrete BaseWebExtensionCollection of WebExtensionProperty items
WebExtensionReferenceCollectionConcrete BaseWebExtensionCollection of WebExtensionReference items

See Also