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

Source

virtual Obj?[] asList()

Returns the collection as a fully resolved sys::List. The list is a list of collectionType.

collectionType

Source

protected Type collectionType

The type of the collection

count

Source

Int? count { private set }

Returns the count of objects in the collection.

countPropertyName

Source

protected Str countPropertyName := "Count"

The name of the COM property which returns the collection count

dispatch

Source

protected Dispatch dispatch { private set }

The COM Collection component

each

Source

virtual Void each(|Obj?,Int callback)

Calls the specified function for every item in the collection

find

Source

virtual Obj? find(|Obj?,Int->Bool callback)

Returns the first item in the collection for which callback returns true. If callback returns false for every item, then return null.

This method is lazy and does not pre-call item for every member in the collection.

item

Source

virtual Obj? item(Int index)

Returns a member of the collection specified by its index.

Override to provide a narrowed return type:

itemMethodName

Source

protected Str itemMethodName := "Item"

The name of the COM method which returns an item in the collection

makeFromDispatch

Source

new makeFromDispatch(Dispatch dispatch, Type collectionType, Bool oneBased := false)

Makes a COM Collection of the given type