toList<T> method

List<T> toList<T>(
  1. T creator(
    1. Pointer<COMObject>
    ), {
  2. int length = 1,
})

Creates a List<T> from the Pointer<COMObject>.

T must be a WinRT type. e.g. IHostName, IStorageFile ...

creator must be specified for the given T. e.g. IHostName.new, IStorageFile.new

length must be equal to the number of elements stored inside the Pointer<COMObject>.

...
final list = pComObject.toList<IHostName>(IHostName.new, length: 4);

{@category winrt}

Implementation

List<T> toList<T>(T Function(Pointer<COMObject>) creator, {int length = 1}) {
  final list = <T>[];
  for (var i = 0; i < length; i++) {
    final element = this[i];
    if (element.ref.lpVtbl == nullptr) {
      break;
    }
    list.add(creator(element));
  }

  return list;
}