IAsyncOperation<TResult>.fromPtr constructor

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

Creates an instance of IAsyncOperation from the given ptr.

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

doubleType must be specified if TResult is double.

final asyncOperation =
    IAsyncOperation<double>.fromPtr(ptr, doubleType: DoubleType.float);

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,
  DoubleType? doubleType,
  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 == double) {
    if (doubleType == null) throw ArgumentError.notNull('doubleType');
    final asyncOperation = switch (doubleType) {
      DoubleType.double => _IAsyncOperationDouble.fromPtr(ptr),
      DoubleType.float => _IAsyncOperationFloat.fromPtr(ptr),
    };
    return asyncOperation as IAsyncOperation<TResult>;
  }

  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 (isSubtypeOfWinRTFlagsEnum<TResult>()) {
    if (enumCreator == null) throw ArgumentError.notNull('enumCreator');
    return _IAsyncOperationWinRTFlagsEnum.fromPtr(ptr,
        enumCreator: enumCreator);
  }

  if (isSubtypeOfWinRTEnum<TResult>()) {
    if (enumCreator == null) throw ArgumentError.notNull('enumCreator');
    return _IAsyncOperationWinRTEnum.fromPtr(ptr, enumCreator: enumCreator);
  }

  if (isSubtypeOfWinRTStruct<TResult>()) {
    if (TResult == LoadMoreItemsResult) {
      return _IAsyncOperationLoadMoreItemsResult.fromPtr(ptr)
          as IAsyncOperation<TResult>;
    }
  }

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