IIterable<T>.fromRawPointer constructor

IIterable<T>.fromRawPointer(
  1. Pointer<COMObject> ptr, {
  2. T creator(
    1. Pointer<COMObject>
    )?,
  3. T enumCreator(
    1. int
    )?,
  4. Type? intType,
})

Creates an instance of IIterable using the given ptr.

T must be of type int, String, Uri, WinRT (e.g. IHostName, IStorageFile) or WinRTEnum (e.g. DeviceClass).

intType must be specified if T is int. Supported types are: Int16, Int32, Int64, Uint8, Uint16, Uint32, Uint64.

final iterable = IIterable<int>.fromRawPointer(ptr, intType: Uint64);

creator must be specified if T is a WinRT type.

final iterable = IIterable<StorageFile>.fromRawPointer(ptr,
   creator: StorageFile.fromRawPointer);

enumCreator and intType must be specified if T is a WinRTEnum.

final iterable = IIterable<DeviceClass>.fromRawPointer(ptr,
    enumCreator: DeviceClass.from, intType: Int32);

Implementation

IIterable.fromRawPointer(
  super.ptr, {
  T Function(Pointer<COMObject>)? creator,
  T Function(int)? enumCreator,
  Type? intType,
})  : _creator = creator,
      _enumCreator = enumCreator,
      _intType = intType {
  if (!isSameType<T, int>() &&
      !isSameType<T, String>() &&
      !isSameType<T, Uri>() &&
      !isSubtypeOfInspectable<T>() &&
      !isSubtypeOfWinRTEnum<T>()) {
    throw ArgumentError.value(T, 'T', 'Unsupported type');
  }

  if (isSameType<T, int>() && intType == null) {
    throw ArgumentError.notNull('intType');
  }

  if (isSubtypeOfInspectable<T>() && creator == null) {
    throw ArgumentError.notNull('creator');
  }

  if (isSubtypeOfWinRTEnum<T>()) {
    if (enumCreator == null) throw ArgumentError.notNull('enumCreator');
    if (intType == null) throw ArgumentError.notNull('intType');
  }

  if (intType != null && !supportedIntTypes.contains(intType)) {
    throw ArgumentError.value(intType, 'intType', 'Unsupported type');
  }
}