toMap<K, V> static method

Map<K, V> toMap<K, V>(
  1. IIterator<IKeyValuePair<K, V>> iterator, {
  2. IKeyValuePair<K, V> creator(
    1. Pointer<COMObject>
    )?,
  3. int length = 1,
})

Implementation

static Map<K, V> toMap<K, V>(
  IIterator<IKeyValuePair<K, V>> iterator, {
  IKeyValuePair<K, V> Function(Pointer<COMObject>)? creator,
  int length = 1,
}) {
  final pKeyValuePairArray = calloc<COMObject>(length);

  try {
    iterator.getMany(length, pKeyValuePairArray);
    final keyValuePairs = pKeyValuePairArray.toList<IKeyValuePair<K, V>>(
        creator ?? IKeyValuePair.fromRawPointer,
        length: length);
    final map = Map.fromEntries(
        keyValuePairs.map((kvp) => MapEntry(kvp.key, kvp.value)));

    return Map.unmodifiable(map);
  } finally {
    free(pKeyValuePairArray);
    free(iterator.ptr);
  }
}