Recent

Author Topic: How to use custom attribute with methods ?  (Read 172 times)

mohsenti

  • Jr. Member
  • **
  • Posts: 57
How to use custom attribute with methods ?
« on: October 30, 2020, 06:32:45 pm »
I have implement restful framework over Custom Attributes but fpc doesn't allow attribute with methods and generate "Sample.lpr(19,5) Error: Unbound custom attribute: "APostAttribute"." compiler error.

Is there a way to set attribute for methods ?

My attributes

Code: Pascal  [Select][+][-]
  1.  
  2. { AAttribute }
  3.  
  4.   AAttribute = class(TCustomAttribute)
  5.   public
  6.     constructor Create;
  7.   end;
  8.  
  9.   { ARequestAttribute }
  10.  
  11.   ARequestAttribute = class(AAttribute)
  12.   private
  13.     FURL: string;
  14.   public
  15.     constructor Create(AUrl: string);
  16.     property URL: string read FURL write FURL;
  17.   end;
  18.  
  19.   { APostAttribute }
  20.  
  21.   APostAttribute = class(ARequestAttribute)
  22.   public
  23.   end;
  24.  
  25.   { AGetAttribute }
  26.  
  27.   AGetAttribute = class(ARequestAttribute)
  28.   public
  29.   end;
  30.  
  31.   { AGParamAttribute }
  32.  
  33.   AGParamAttribute = class(AAttribute)
  34.   public
  35.   end;
  36.  
  37.   { APParamAttribute }
  38.  
  39.   APParamAttribute = class(AAttribute)
  40.   public
  41.   end;
  42.  
  43.  

And Service Interface
Code: Pascal  [Select][+][-]
  1.  
  2. IFakeRest = interface(IInvokable)
  3.     ['{C43D0D3C-9A91-4DA4-BE74-97B7DF9E2A2B}']
  4.     [APostAttribute('/test')]
  5.     function test(a: boolean; b: integer): string;
  6. end;
  7.  
  8.  
« Last Edit: October 30, 2020, 06:34:40 pm by mohsenti »

PascalDragon

  • Hero Member
  • *****
  • Posts: 2433
  • Compiler Developer
Re: How to use custom attribute with methods ?
« Reply #1 on: October 31, 2020, 11:06:25 am »
Is there a way to set attribute for methods ?

FPC currently only supports binding attributes to types and published properties. Anything more requires support for Extended RTTI which is planned, but there's no time estimate yet.

 

TinyPortal © 2005-2018