CustomAttribute.fromToken constructor

CustomAttribute.fromToken(
  1. Scope scope,
  2. int token
)

Creates a custom attribute object from a provided token.

Implementation

factory CustomAttribute.fromToken(Scope scope, int token) =>
    using((Arena arena) {
      final ptkObj = arena<mdToken>();
      final ptkType = arena<mdToken>();
      final ppBlob = arena<UVCP_CONSTANT>();
      final pcbBlob = arena<ULONG>();

      final reader = scope.reader;
      final hr = reader.GetCustomAttributeProps(
          token, ptkObj, ptkType, ppBlob, pcbBlob);
      if (SUCCEEDED(hr)) {
        final memberRef = MemberRef.fromToken(scope, ptkType.value);
        final constructorTypeDef =
            TypeDef.fromToken(scope, memberRef.referencedToken);
        return CustomAttribute(
            scope,
            token,
            ptkObj.value,
            memberRef,
            constructorTypeDef,
            ptkType.value,
            ppBlob.value.asTypedList(pcbBlob.value));
      } else {
        throw WindowsException(hr);
      }
    });