-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuZauberkasten.pas
38 lines (31 loc) · 936 Bytes
/
uZauberkasten.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
unit uZauberkasten;
interface
uses
System.SysUtils,
System.Rtti;
type
TMyAttributes = class(TCustomAttribute)
public
procedure Doit(const Instance: TObject; const Method: TRttiMethod; const Args: TArray<TValue>; const result: TValue); virtual; abstract;
end;
TZauberkasten = class
public
class function Zaubern(obj: TObject): TVirtualMethodInterceptor;
end;
implementation
class function TZauberkasten.Zaubern(obj: TObject): TVirtualMethodInterceptor;
begin
result:=TVirtualMethodInterceptor.Create(obj.ClassType);
result.OnBefore:=
procedure(Instance: TObject; Method: TRttiMethod;
const Args: TArray<TValue>; out DoInvoke: Boolean; out result: TValue)
var
at: TCustomAttribute;
begin
for at in Method.GetAttributes() do
if (at is TMyAttributes) then
TMyAttributes(at).Doit(Instance, method, args, result);
end;
result.Proxify(obj);
end;
end.