IAsyncOperation<TResult>.fromPtr constructor

IAsyncOperation<TResult>.fromPtr(
  1. Pointer<COMObject> ptr, {
  2. TResult creator(
    1. Pointer<COMObject>
    )?,
  3. TResult enumCreator(
    1. int
    )?,
  4. IntType? intType,
})

Creates an instance of IAsyncOperation from the given ptr.

TResult must be of type bool, Guid, int, Object?, String, Uri?, IInspectable? (e.g. StorageFile?) or WinRTEnum (e.g. LaunchUriStatus).

intType must be specified if TResult is int.

final asyncOperation = IAsyncOperation<int>.fromPtr(ptr,
    intType: IntType.uint64);

creator must be specified if TResult is IInspectable?.

...
final asyncOperation = IAsyncOperation<StorageFile?>(ptr,
    creator: StorageFile.fromPtr);

enumCreator must be specified if TResult is WinRTEnum.

final asyncOperation = IAsyncOperation<LaunchUriStatus>.fromPtr
    (ptr, enumCreator: LaunchUriStatus.from);

Implementation

factory IAsyncOperation.fromPtr(
  Pointer<COMObject> ptr, {
  TResult Function(Pointer<COMObject>)? creator,
  TResult Function(int)? enumCreator,
  IntType? intType,
}) {
  if (TResult == bool) {
    return _IAsyncOperationBool.fromPtr(ptr) as IAsyncOperation<TResult>;
  }

  if (TResult == Guid) {
    return _IAsyncOperationGuid.fromPtr(ptr) as IAsyncOperation<TResult>;
  }

  if (isSubtypeOfInspectable<TResult>()) {
    if (creator == null) throw ArgumentError.notNull('creator');
    return _IAsyncOperationInspectable.fromPtr(ptr, creator: creator);
  }

  if (TResult == int) {
    if (intType == null) throw ArgumentError.notNull('intType');
    final asyncOperation = switch (intType) {
      IntType.int16 => _IAsyncOperationInt16.fromPtr(ptr),
      IntType.int32 => _IAsyncOperationInt32.fromPtr(ptr),
      IntType.int64 => _IAsyncOperationInt64.fromPtr(ptr),
      IntType.uint8 => _IAsyncOperationUint8.fromPtr(ptr),
      IntType.uint16 => _IAsyncOperationUint16.fromPtr(ptr),
      IntType.uint32 => _IAsyncOperationUint32.fromPtr(ptr),
      IntType.uint64 => _IAsyncOperationUint64.fromPtr(ptr)
    };
    return asyncOperation as IAsyncOperation<TResult>;
  }

  if (isNullableObjectType<TResult>()) {
    return _IAsyncOperationObject.fromPtr(ptr) as IAsyncOperation<TResult>;
  }

  if (TResult == String) {
    return _IAsyncOperationString.fromPtr(ptr) as IAsyncOperation<TResult>;
  }

  if (isSameType<TResult, Uri?>()) {
    return _IAsyncOperationUri.fromPtr(ptr) as IAsyncOperation<TResult>;
  }

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

    if (isSubtypeOfWinRTFlagsEnum<TResult>()) {
      return _IAsyncOperationWinRTFlagsEnum.fromPtr(ptr,
          enumCreator: enumCreator);
    }

    return _IAsyncOperationWinRTEnum.fromPtr(ptr, enumCreator: enumCreator);
  }

  throw ArgumentError.value(TResult, 'TResult', 'Unsupported type');
}