IVectorView<T>.fromRawPointer constructor

IVectorView<T>.fromRawPointer(
  1. Pointer<COMObject> ptr, {
  2. required String iterableIid,
  3. T creator(
    1. Pointer<COMObject>
    )?,
  4. T enumCreator(
    1. int
    )?,
  5. Type? intType,
})

Creates an instance of IVectorView using the given ptr and iterableIid.

iterableIid must be the IID of the IIterable<T> interface (e.g. IID_IIterable_String).

T must be of type int, Uri, String, 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 vectorView = IVectorView<int>.fromRawPointer(ptr, intType: Uint64);

creator must be specified if T is a WinRT type.

final vectorView = IVectorView<StorageFile>.fromRawPointer(ptr,
   creator: StorageFile.fromRawPointer);

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

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

Implementation

IVectorView.fromRawPointer(
  super.ptr, {
  required String iterableIid,
  T Function(Pointer<COMObject>)? creator,
  T Function(int)? enumCreator,
  Type? intType,
})  : _iterableIid = iterableIid,
      _creator = creator,
      _enumCreator = enumCreator,
      _intType = intType {
  if (!isSameType<T, int>() &&
      !isSameType<T, Uri>() &&
      !isSameType<T, String>() &&
      !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');
  }
}