customAttributes property

List<CustomAttribute> customAttributes

Enumerate all attributes that this object has.

Implementation

List<CustomAttribute> get customAttributes {
  if (_customAttributes.isEmpty) {
    using((Arena arena) {
      final phEnum = arena<HCORENUM>();
      final rAttrs = arena<mdCustomAttribute>();
      final pcAttrs = arena<ULONG>();

      // Certain TokenObjects may not have a valid token (e.g. a return
      // type has a token of 0). In this case, we return an empty set, since
      // calling EnumCustomAttributes with a scope of 0 will return all
      // attributes on all objects in the scope.
      if (!isResolvedToken) return <CustomAttribute>[];

      var hr =
          reader.EnumCustomAttributes(phEnum, token, 0, rAttrs, 1, pcAttrs);
      while (hr == S_OK) {
        final attrToken = rAttrs.value;

        _customAttributes.add(CustomAttribute.fromToken(scope, attrToken));
        hr =
            reader.EnumCustomAttributes(phEnum, token, 0, rAttrs, 1, pcAttrs);
      }
      reader.CloseEnum(phEnum.value);
    });
  }
  return _customAttributes;
}