abstract classafFancom::Collection
sys::Obj afFancom::Collection
A utility class that emulates a COM Collection object. Collection
is designed to be subclassed.
For Fancom to instantiate the collection subclass it needs a ctor similar to:
new makeFromDispatch(Dispatch dispatch) : super(dispatch, MyCollectionType#) { }
The collection type should be a valid Fancom type or a Fancom surrogate.
Subclasses my override methods to narrow the return types:
override MyType? item(Int index) { super.item(index) }
When doing so, ensure the return type is declared as nullable. See Covariance, value types, and nullability
If calculated properties are ever allowed to be in Mixins, this class could be converted to a Mixin. See Mixin Calculated Fields
- asList
virtual Obj?[] asList()
Returns the collection as a fully resolved sys::List. The list is a list of
collectionType
.- collectionType
protected Type collectionType
The type of the collection
- count
Int? count { private set }
Returns the count of objects in the collection.
- countPropertyName
protected Str countPropertyName := "Count"
The name of the COM property which returns the collection count
- dispatch
protected Dispatch dispatch { private set }
The COM Collection component
- each
virtual Void each(|Obj?,Int callback)
Calls the specified function for every item in the collection
- find
virtual Obj? find(|Obj?,Int->Bool callback)
Returns the first item in the collection for which
callback
returnstrue
. Ifcallback
returnsfalse
for every item, then returnnull
.This method is lazy and does not pre-call item for every member in the collection.
- item
Returns a member of the collection specified by its index.
Override to provide a narrowed return type:
- itemMethodName
protected Str itemMethodName := "Item"
The name of the COM method which returns an item in the collection
- makeFromDispatch
new makeFromDispatch(Dispatch dispatch, Type collectionType, Bool oneBased := false)
Makes a COM Collection of the given type